Can ansible parse and act based on information in an input xml / yaml / json file?

638 views
Skip to first unread message

Lax Clarke

unread,
Jul 20, 2016, 10:53:18 AM7/20/16
to Ansible Project
Is there a way ansible can use an input file like xml / yaml / json to control its actions?

I know "lookup" works on "flat" file types, but I cannot find reference to a feature that can walk a tree-like hierarchical input file type (e.g., xml / yaml / json ).

James

unread,
Jul 20, 2016, 2:24:16 PM7/20/16
to Ansible Project
The right answer to this probably depends on where this "input file" is located (on Ansible server or on hosts being modified) and what you're wanting to do with the information.  But in general, if you are talking about reading a YAML or JSON file into variables for use within a playbook you can take a look at include_vars.  Hosts can also provide local JSON or INI information via *.fact files in /etc/ansible/facts.d.  Or you can read YAML information specific to hosts, groups, etc via all the variable directory conventions (group_vars, host_vars, etc) 

If you can give some further details, someone may have a better plan.

K Dawg

unread,
Jul 22, 2016, 11:31:20 AM7/22/16
to Ansible Project


On Wednesday, July 20, 2016 at 2:24:16 PM UTC-4, James wrote:
The right answer to this probably depends on where this "input file" is located (on Ansible server or on hosts being modified) and what you're wanting to do with the information.  But in general, if you are talking about reading a YAML or JSON file into variables for use within a playbook you can take a look at include_vars.  Hosts can also provide local JSON or INI information via *.fact files in /etc/ansible/facts.d.  Or you can read YAML information specific to hosts, groups, etc via all the variable directory conventions (group_vars, host_vars, etc) 

If you can give some further details, someone may have a better plan.

Thanks for response.
I mean, I want to configure something based on an xml file, but the number of various sections is not known before handle. And the existence or non-existence of various sections (i.e., XML nodes) is also not known before hand.  Same with attributes.

I think i need to suck into an XML Dom and then trigger actions while walking the DOM.

K Dawg

unread,
Jul 22, 2016, 1:09:38 PM7/22/16
to Ansible Project
As an example, 

I have a 3 level tree structure that defines a config.

top level list:  A , B , C, D, ... <-- note the ellipses

Then under A:  x, y, z, .... <-- note the ellipses

Then under x:   i, j, k, .... <--- note the ellipses

And the pattern can continue.

Moreover, there can be absent configs too.
Reply all
Reply to author
Forward
0 new messages