# Have some way to merge the 'host' INI inventory and group\_vars/$service  to become a single $service.yml?

**URL:** <https://forum.ansible.com/t/have-some-way-to-merge-the-host-ini-inventory-and-group-vars-service-to-become-a-single-service-yml/25689>\
**Category:** Ansible Project\
**Created:** [October 5, 2017, 4:12pm UTC](https://forum.ansible.com/t/have-some-way-to-merge-the-host-ini-inventory-and-group-vars-service-to-become-a-single-service-yml/25689 "2017-10-05T16:12:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpereira](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@jpereira](https://forum.ansible.com/u/jpereira)\
**Post date:** [October 5, 2017, 4:12pm UTC](https://forum.ansible.com/t/have-some-way-to-merge-the-host-ini-inventory-and-group-vars-service-to-become-a-single-service-yml/25689/1 "2017-10-05T16:12:44Z")

</div>

Hi List,

Today, we are using the approach as suggested by the official documentation (directory layout) [http://docs.ansible.com/ansible/latest/playbooks\_best\_practices.html](http://docs.ansible.com/ansible/latest/playbooks_best_practices.html)  
but, if you have a big number of regions/different-pops and huge number of servers. so, It’s become a bit confused to be maintained.

So, my goal is to find a way to merge the ‘host’ inventory that has the usual “[services1]” and ‘groups\_vars/services1’ to become a single ‘services.yml’, for me it is the best way.

p.s: I tried to use the INI format, but the fact is because do not fit well due to we use big number of variables (strings, arrays) for different regions & pops.

Thanks in advance,

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 5, 2017, 4:37pm UTC](https://forum.ansible.com/t/have-some-way-to-merge-the-host-ini-inventory-and-group-vars-service-to-become-a-single-service-yml/25689/2 "2017-10-05T16:37:17Z")

</div>

in 2.4 you can use ansible-inventory to dump a yaml/json  
representation of the inventory.

---

<div class="post-metadata">

**Author:** ![Jorge\_Pereira](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@Jorge\_Pereira](https://forum.ansible.com/u/Jorge_Pereira)\
**Post date:** [October 5, 2017, 5:41pm UTC](https://forum.ansible.com/t/have-some-way-to-merge-the-host-ini-inventory-and-group-vars-service-to-become-a-single-service-yml/25689/3 "2017-10-05T17:41:50Z")

</div>

Brian,

I tried it, but the response is very polluted. I am looking for something more simple.

e.g:

# cat hosts

[web:children]  
web-region1  
…

[web-region1]  
1.2.3.4 var1=“[1, 2, 3]” var2=“caipirinha”  
1.2.3.5 var1=“[6, 7, 8]” var2=“caipirinha-com-gelo”  
…

# cat group\_vars/web-region1

var\_name1: “1, 2”  
var\_name2: “3, 4”

…

So, the expectation should be to create a single

# cat web-region1.yml

web-region1:

hosts:  
1.2.3.4:  
var1: “[1, 2, 3]”  
var2: “caipirinha”

1.2.3.5:  
var1: “[6, 7, 8]”  
var2: “caipirinha-com-gelo”

vars:

var\_name1: “1, 2”  
var\_name2: “3, 4”

---

<div class="post-metadata">

**Author:** ![Jorge\_Pereira](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@Jorge\_Pereira](https://forum.ansible.com/u/Jorge_Pereira)\
**Post date:** [October 6, 2017, 5:25am UTC](https://forum.ansible.com/t/have-some-way-to-merge-the-host-ini-inventory-and-group-vars-service-to-become-a-single-service-yml/25689/4 "2017-10-06T05:25:48Z")

</div>

Hi Guys,

I just created the simple tool here [https://github.com/jpereira/ansible-tools/](https://github.com/jpereira/ansible-tools/) to do that.
