Hello,
I just started playing with ansible a couple of weeks ago … and so far, I must say that it looks like The Tools I’ve been looking for a long time!
Being a newbie, I am facing newbie’s problem…
I would like to get the IP address of a group of server in my host file, and I really can’t figure out to do this properly.
This is the group in my host file:
[tools]
lot-devbld-01
lot-devtls-01
lot-jira-01
The part of the playbook:
- name: test groups
command: echo {{ hostvars[$item][ansible_eth0][ipv4][address] }}
with_items: groups.tools
and, what I get …
REMOTE_MODULE command echo {{hostvars[lot-devtls-01][ansible_eth0][ipv4][address]}}
changed: [lmesdbx1-01] => (item=lot-devtls-01) => {“changed”: true, “cmd”: [“echo”, “{{hostvars[lot-devtls-01][ansible_eth0][ipv4][address]}}”], “delta”: “0:00:00.001929”, “end”: “2013-09-10 15:26:01.354081”, “item”: “lot-devtls-01”, “rc”: 0, “start”: “2013-09-10 15:26:01.352152”, “stderr”: “”, “stdout”: “{{hostvars[lot-devtls-01][ansible_eth0][ipv4][address]}}”}
REMOTE_MODULE command echo {{hostvars[lot-jira-01][ansible_eth0][ipv4][address]}}
changed: [lmesdbx1-01] => (item=lot-jira-01) => {“changed”: true, “cmd”: [“echo”, “{{hostvars[lot-jira-01][ansible_eth0][ipv4][address]}}”], “delta”: “0:00:00.002107”, “end”: “2013-09-10 15:26:05.325616”, “item”: “lot-jira-01”, “rc”: 0, “start”: “2013-09-10 15:26:05.323509”, “stderr”: “”, “stdout”: “{{hostvars[lot-jira-01][ansible_eth0][ipv4][address]}}”}
REMOTE_MODULE command echo {{hostvars[lot-devbld-01][ansible_eth0][ipv4][address]}}
changed: [lmesdbx1-01] => (item=lot-devbld-01) => {“changed”: true, “cmd”: [“echo”, “{{hostvars[lot-devbld-01][ansible_eth0][ipv4][address]}}”], “delta”: “0:00:00.002060”, “end”: “2013-09-10 15:26:09.461217”, “item”: “lot-devbld-01”, “rc”: 0, “start”: “2013-09-10 15:26:09.459157”, “stderr”: “”, “stdout”: “{{hostvars[lot-devbld-01][ansible_eth0][ipv4][address]}}”}
How should I do that to get the hostvars interpreted properly?
and more generally, could you point me to some documentation on the variable syntax? (ie: when do I need a $, when to use groups.tools rather than groups[‘tools’], etc …)
Thank you.
Fred