generate config file from template with N dimensional array

I use roles and testXX/group_vars/all to define a great many things for each environments.

I have to build xml files that contain two values at least in each iteration. The example below has pool1 and pool2, and within those pools we have server1, server2 etc.

I can’t get my head around how to template this, and how to define arrays in group_vars to work with the templates and/or playbook. I hope this makes sense.

pool1 server1 hostname1 /path/to/somewhere server3 hostname2 /path/to/somewhere pool2 server2 hostname3 /path/to/somewhere server2 hostname4 /path/to/somewhere

I would like my all file to be something like
pools:

  • pool1
  • server1, hostname1
  • server3, hostname2
  • pool2
  • server2, hostname3
    etc

I don’t have anything quite this complicated, but I think that you should be able to do something like this…

pool_list:

  • { name: pool1, server_list: {name: server1, hostname: hostname1, }, {name: server2, hostname: hostname2} }
  • { name: pool2, server_list: {name: server3, hostname: hostname3}, {name: server4, hostname: hostname4} }

{% for item in pool_list %}

{{ item.name }} {% for server in item.server_list %} {{ server.name }} {{ server.hostname }} /path/to/somewhere

{% endfor %}

{% endfor %}

I’ve never tried this, but it might be worth looking at…

Adam