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

**URL:** <https://forum.ansible.com/t/can-ansible-parse-and-act-based-on-information-in-an-input-xml-yaml-json-file/22058>\
**Category:** Ansible Project\
**Created:** [July 20, 2016, 2:41pm UTC](https://forum.ansible.com/t/can-ansible-parse-and-act-based-on-information-in-an-input-xml-yaml-json-file/22058 "2016-07-20T14:41:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![K\_Dawg](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@K\_Dawg](https://forum.ansible.com/u/K_Dawg)\
**Post date:** [July 20, 2016, 2:41pm UTC](https://forum.ansible.com/t/can-ansible-parse-and-act-based-on-information-in-an-input-xml-yaml-json-file/22058/1 "2016-07-20T14:41:44Z")

</div>

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 ).

---

<div class="post-metadata">

**Author:** ![James6](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@James6](https://forum.ansible.com/u/James6)\
**Post date:** [July 20, 2016, 6:24pm UTC](https://forum.ansible.com/t/can-ansible-parse-and-act-based-on-information-in-an-input-xml-yaml-json-file/22058/2 "2016-07-20T18:24:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![K\_Dawg](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@K\_Dawg](https://forum.ansible.com/u/K_Dawg)\
**Post date:** [July 22, 2016, 3:31pm UTC](https://forum.ansible.com/t/can-ansible-parse-and-act-based-on-information-in-an-input-xml-yaml-json-file/22058/3 "2016-07-22T15:31:20Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![K\_Dawg](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@K\_Dawg](https://forum.ansible.com/u/K_Dawg)\
**Post date:** [July 22, 2016, 5:09pm UTC](https://forum.ansible.com/t/can-ansible-parse-and-act-based-on-information-in-an-input-xml-yaml-json-file/22058/4 "2016-07-22T17:09:38Z")

</div>

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.
