Ansible parser - python

23 views
Skip to first unread message

Nemania Borovits

unread,
Mar 30, 2020, 10:09:45 AM3/30/20
to Ansible Development
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

Matt Martz

unread,
Mar 30, 2020, 11:07:44 AM3/30/20
to Nemania Borovits, Ansible Development
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 ansible-deve...@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.


--
Matt Martz
@sivel
sivel.net

Nemania Borovits

unread,
Mar 30, 2020, 11:48:56 AM3/30/20
to Ansible Development
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.

Matt Martz

unread,
Mar 30, 2020, 12:03:31 PM3/30/20
to Nemania Borovits, Ansible Development
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.




To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@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.
Reply all
Reply to author
Forward
0 new messages