Read the docs about "group_vars/" and "host_vars/" directories.
This is a better way to organize variables than embedding them in the file for nearly all cases. On Mon, Feb 24, 2014 at 9:06 AM, Stuart Golightly <[email protected]>wrote: > Afternoon all > > > > I've got a bunch of servers, each running two instances of an application, > which results in a mapping like this: > > > > serverA inst-1 > > serverA inst-2 > > serverB inst-3 > > serverB inst-4 > > serverC inst-5 > > serverC inst-6 > > > > I was hoping to use inventory vars to do some work on the instances, so I > thought of using an inventory file looking like this: > > > > serverA inst_name=inst-1 > > serverA inst_name=inst-2 > > serverB inst_name=inst-3 > > serverB inst_name=inst-4 > > serverC inst_name=inst-5 > > serverC inst_name=inst-6 > > > > Looking through the variable documentation, this idea seems doomed to > failure, as the second var definition appears to overwrite the first, > meaning that only "inst-2", "inst-4" and "inst-6" get processed. Running > this inventory through the debug module gives that result.. > > > > [sgolightly@XXX ansible]$ ansible -i > ./inventories/var-test-inventory.hosts all -m debug -a "var={{inst_name}}" > > serverC | success >> { > > "inst-6": "{{ inst-6 }}" > > } > > > > serverA | success >> { > > "inst-2": "{{ inst-2 }}" > > } > > > > serverB | success >> { > > "inst-4": "{{ inst-4 }}" > > } > > > > [sgolightly@XXX ansible]$ > > > > Apart from creating two inventory files - one for odd numbered instances > and one for even - has anyone got any bright ideas how this kind of > situation can be handled. Or is two inventory files the easiest and best > way? > > > > The instance names are used in directory names, config files and the like, > so the names have to stay. > > > > Stuart > > > > -- > > Stuart Golightly > > Systems administrator > > Hotels.com > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/778b581ccca948828244684989d3b0db%40DBCXEXCHMBX002.SEA.CORP.EXPECN.com > . > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEVJ8QMkXWBL1t9cuE3G5bX68RqK4tn_6k6%2BCQ%3DHcCxdLSCUtA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
