As asked here

http://stackoverflow.com/questions/30985183/variable-as-array-object-key-in-ansible


I am writing a playbook that creates a network with a name I assign. Later 
on in the playbook I need to access the IP that is assigned by this network 
task, so I get it from the hostvars. So for example it if I was calling the 
network 'my_website' the value I would be targeting in hostvars would be

server: 
"{{hostvars.localhost.rax_nfs.results[0].success[0].rax_addresses.my_website[0].addr}}"

This is fine, but I want to name the network based on the contents of a 
variable passed in by a var file to make it reusable across multiple 
setups, and then still be able to get that IP back, so

network_label: "{{ my_website }}"
server: 
"{{hostvars.localhost.rax_nfs.results[0].success[0].rax_addresses.network_label[0].addr}}"

Obviously this doesn't work as it just assigns a string. How do I use 
network_label as the key inside another variable? Like in php something like

$array[$variable], or $object->$variable

Is this possible?

-- 
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/778211ae-a904-4a31-9174-db9f483079ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to