There isn't really an AST for Ansible. Ultimately, there are ways to achieve this, they just aren't "supported". You could use the Ansible code to do it, but you would need to understand that it could break at any point in time without notification.
Or you could write your own tooling from scratch. I wrote a proof of concept tool recently, that used the Ansible code. You can look at it for inspiration, but again, it may stop working at any point in time. https://gist.github.com/sivel/1f850b7f577b9dc9466293034c82b19d On Mon, Mar 30, 2020 at 10:49 AM Nemania Borovits <nemaniaborov...@gmail.com> wrote: > Thanks for the quick answer Matt. For each ansible task, i want to get > the module, parameters, etc. I want to tokenize the task body for ML > purposes. Additionally, is there an AST (abstract syntax tree) for > Ansible...? > > On Monday, March 30, 2020 at 5:07:44 PM UTC+2, Matt Martz wrote: >> >> Ansible does not expose a python API for developers for this purpose. >> Under the hood, it is pyyaml that parses the files. I don't know what your >> end goal is, so I cannot really make any useful recommendation, other than >> to use pyyaml. >> >> On Mon, Mar 30, 2020 at 9:09 AM Nemania Borovits <nemania...@gmail.com> >> wrote: >> >>> Hello! I need to parse ansible files effectively. Is there any python >>> library which i can use to parse .yml/.yaml files which contain ansible >>> deployments...? Besides pyyaml or ruamel.yaml >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ansible Development" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to ansibl...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/ansible-devel/8545abe9-c29a-4cab-9a0e-d7fe66712cd7%40googlegroups.com >>> <https://groups.google.com/d/msgid/ansible-devel/8545abe9-c29a-4cab-9a0e-d7fe66712cd7%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> Matt Martz >> @sivel >> sivel.net >> > -- > You received this message because you are subscribed to the Google Groups > "Ansible Development" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to ansible-devel+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-devel/0700a738-4ee9-4845-8186-2da618fc5815%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-devel/0700a738-4ee9-4845-8186-2da618fc5815%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Matt Martz @sivel sivel.net -- You received this message because you are subscribed to the Google Groups "Ansible Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/CAD8N0v_YhqgdNzYjt-WApg3P2%2BWWM8Y7tOqvVdfhPCqG47g45A%40mail.gmail.com.