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

40 views
Skip to first unread message

jper...@zenedge.com

unread,
Oct 5, 2017, 12:12:44 PM10/5/17
to Ansible Project
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
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,

--
Jorge Pereira

Brian Coca

unread,
Oct 5, 2017, 12:37:35 PM10/5/17
to Ansible Project
in 2.4 you can use ansible-inventory to dump a yaml/json
representation of the inventory.





--
----------
Brian Coca

Jorge Pereira

unread,
Oct 5, 2017, 1:41:50 PM10/5/17
to Ansible Project
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"
#

Somebody knows if have some way? Any clue?

Jorge Pereira

unread,
Oct 6, 2017, 1:25:48 AM10/6/17
to Ansible Project
Hi Guys,

I just created the simple tool here https://github.com/jpereira/ansible-tools/ to do that. 
Reply all
Reply to author
Forward
0 new messages