I think I have got to a point where I really get confused about teh way variables are used. I need some clarity to understand how you would do this with ansible:
Lets say I have one single hosts where I want to create a collection of directories in /data/db/{project1,project2,n}
I am using the structure described in the Ansible best practices:
Sorry Guillem, I typed that up in a hurry. I should have quoted the
key 'domain' like so:
- debug: msg="{{ project[item]['domain'] }}"
or as use have discovered, the equivalent:
{{ project[item].domain }}
Mixing dictionary lookup forms (that is, using both dots and brackets)
can be a little confusing to other people reading the code, so I
prefer to use one or the other but not both at the same time.
Suite 1415
401 Docklands Drive
Docklands VIC 3008 Australia
"All parts should go together without forcing. You must remember that
the parts you are reassembling were disassembled by you. Therefore,
if you can't get them together again, there must be a reason. By all
means, do not use a hammer." -- IBM maintenance manual, 1925
Many thanks for this. I am finding lots of power in Ansible, but also lots of ‘hidden’ gotchas. I have now revamped my configuration to be used with your suggestion and it works really well.
The next pit I found was in the variable precedence.
I honestly understood from the best practice and the docuementation that if you had a role called web, then placing a file called web.yml in there would make the tasks in web to lookup variables stored in web.yml. However if I had another file lets say test.yml before, it would use it instead. So in order to overcome this problem I see two solutions, manually forcing vars_file from each playbook or store all variables for all playbooks in one file. I’m still deciding what would be the best behavior for the future…
Many thanks for your input so far, you healped me overcome a fundamental issue I had in here.