# managing xml fragments a la lineinfile

**URL:** <https://forum.ansible.com/t/managing-xml-fragments-a-la-lineinfile/23599>\
**Category:** Ansible Project\
**Created:** [January 30, 2017, 7:24pm UTC](https://forum.ansible.com/t/managing-xml-fragments-a-la-lineinfile/23599 "2017-01-30T19:24:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [January 30, 2017, 7:24pm UTC](https://forum.ansible.com/t/managing-xml-fragments-a-la-lineinfile/23599/1 "2017-01-30T19:24:27Z")

</div>

Does anyone here a good tip for managing parts of xml files  
(like lineinfile / blockinfile but xml-aware)?

I have several fairly complex apps to manage, each with their own role.  
Ideally they'd each manage their own subset of the domain.xml,  
which rules out a single domain.xml template.

ansible-xml looked perfect until I tried it and found it doesn't actually  
work ☹ [[https://github.com/cmprescott/ansible-xml/issues/55](https://github.com/cmprescott/ansible-xml/issues/55) ]

My Plan B (make that 'H' by now) would be to have a master template  
that pulled in 'sub-templates' via lookup\_template() , but that sounds like  
it'll get messy fast and involve hardcoding roles together.

Does everyone just template their XML? Are you crazy kids all using  
YAML and JSON nowadays?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 30, 2017, 7:47pm UTC](https://forum.ansible.com/t/managing-xml-fragments-a-la-lineinfile/23599/2 "2017-01-30T19:47:13Z")

</div>

If each subset can be divided in to files that then can be assembled into one big file you can check out the Assemble module.  
[https://docs.ansible.com/ansible/assemble\_module.html](https://docs.ansible.com/ansible/assemble_module.html)

---

<div class="post-metadata">

**Author:** ![davros1984](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@davros1984](https://forum.ansible.com/u/davros1984)\
**Post date:** [January 31, 2017, 12:54pm UTC](https://forum.ansible.com/t/managing-xml-fragments-a-la-lineinfile/23599/3 "2017-01-31T12:54:47Z")

</div>

Dick - it is do-able. I have done this for the app servers in my current contract. I would have done it where you are now had there been sufficient interest, time or investment.

Firstly, start off with a set xml file for each type of application (messy but necessary)  
Secondly, identify differences and use jinja2 to have blocks to manage those unique bits of the jb config so that you can eventually have 1 master xml file and then sub-xml (child) templates purely for the unique blocks.

However, you have to be very strict on future changes made to the domain.xml file via the cli or manual xml changes by admins. Your challenge will be to ensure all changes are pushed to you/other ansible-folk.

It works a treat, but considerable engineering/research/testing required.

DR.
