# accessing facts from from a group

**URL:** <https://forum.ansible.com/t/accessing-facts-from-from-a-group/13450>\
**Category:** Ansible Project\
**Created:** [September 10, 2013, 7:31pm UTC](https://forum.ansible.com/t/accessing-facts-from-from-a-group/13450 "2013-09-10T19:31:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fred\_Badel](https://avatars.discourse-cdn.com/v4/letter/f/f07891/32.png) [@Fred\_Badel](https://forum.ansible.com/u/Fred_Badel)\
**Post date:** [September 10, 2013, 7:31pm UTC](https://forum.ansible.com/t/accessing-facts-from-from-a-group/13450/1 "2013-09-10T19:31:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [September 10, 2013, 7:46pm UTC](https://forum.ansible.com/t/accessing-facts-from-from-a-group/13450/2 "2013-09-10T19:46:01Z")

</div>

​leave out the $ sign:

​​  
​  
command: echo {{hostvars[item][ansible\_eth0][ipv4][address] }}

---

<div class="post-metadata">

**Author:** ![Fred\_Badel](https://avatars.discourse-cdn.com/v4/letter/f/f07891/32.png) [@Fred\_Badel](https://forum.ansible.com/u/Fred_Badel)\
**Post date:** [September 10, 2013, 7:55pm UTC](https://forum.ansible.com/t/accessing-facts-from-from-a-group/13450/3 "2013-09-10T19:55:33Z")

</div>

Hi,

Thanks. In this case I get an error message:

fatal: [lmesdbx1-01] =\> One or more undefined variables: dict object has no element {u’macaddress’: u’00:50:56:a1:01:43’, u’module’: u’e1000’, u’mtu’: 1500, u’active’: True, u’ipv4’: {u’netmask’: u’255.255.255.0’, u’network’: u’xx.xx.xx.0’, u’address’: u’xx.xx.xx.xx’}, u’ipv6’: [{u’scope’: u’link’, u’prefix’: u’64’, u’address’: u’fe80::250:56ff:fea1:143’}], u’device’: u’eth0’, u’type’: u’ether’}

Fred

---

<div class="post-metadata">

**Author:** ![C\_Morgan\_Hamill](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@C\_Morgan\_Hamill](https://forum.ansible.com/u/C_Morgan_Hamill)\
**Post date:** [September 10, 2013, 8:08pm UTC](https://forum.ansible.com/t/accessing-facts-from-from-a-group/13450/4 "2013-09-10T20:08:45Z")

</div>

You'll want:

&nbsp;&nbsp;&nbsp;&nbsp;command: echo {{ hostvars[item]['ansible\_eth0']['ipv4']['address'] }}

---

<div class="post-metadata">

**Author:** ![Fred\_Badel](https://avatars.discourse-cdn.com/v4/letter/f/f07891/32.png) [@Fred\_Badel](https://forum.ansible.com/u/Fred_Badel)\
**Post date:** [September 10, 2013, 8:28pm UTC](https://forum.ansible.com/t/accessing-facts-from-from-a-group/13450/5 "2013-09-10T20:28:22Z")

</div>

Awesome! Thank you!

Fred
