# \-m setup -a filter="ansible\_eth0.ipv4.address" returns no results

**URL:** <https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129>\
**Category:** Ansible Project\
**Created:** [April 29, 2015, 7:04pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129 "2015-04-29T19:04:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barry\_Morrison](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@Barry\_Morrison](https://forum.ansible.com/u/Barry_Morrison)\
**Post date:** [April 29, 2015, 7:04pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/1 "2015-04-29T19:04:57Z")

</div>

So I’m trying to get the IP address of every server via `ansible` and expect to use something like

ansible -i inventory host\_group -m setup -a filter=“ansible\_eth0.ipv4.address” returns no results. It returns something like

`  
server38.prod.foo | success \>\> {  
“ansible\_facts”: {},  
“changed”: false  
}

`

But I can do ansible -i inventory host\_group -m setup -a filter=“ansible\_eth0” and it will return:

`  
server38.prod.foo | success \>\> {  
“ansible\_facts”: {  
“ansible\_eth0”: {  
“active”: true,  
“device”: “eth0”,  
“ipv4”: {  
“address”: “1.2.3.4.”,  
“netmask”: “255.255.255.0”,  
“network”: “1.2.3.0”  
},  
“ipv6”: [  
{  
“address”: “fe11::225:90ff:fe11:1111”,  
“prefix”: “64”,  
“scope”: “link”  
}  
],  
“macaddress”: “00:11:11:11:11:11”,  
“module”: “e1000e”,  
“mtu”: 1500,  
“promisc”: false,  
“type”: “ether”  
}  
},  
“changed”: false  
}

`

So it does return facts…how do I get filter further to return just the IP address?

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [April 29, 2015, 8:06pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/2 "2015-04-29T20:06:13Z")

</div>

One of the notes in the docs of the setup module reads: "the filter option filters only the first level subkey below ansible\_facts." So you don't. Not that way at least.

What about ansible\_all\_ipv4\_addresses?

---

<div class="post-metadata">

**Author:** ![Barry\_Morrison](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@Barry\_Morrison](https://forum.ansible.com/u/Barry_Morrison)\
**Post date:** [April 29, 2015, 8:12pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/3 "2015-04-29T20:12:04Z")

</div>

Yeah, I’m aware of ansible\_all\_ipv4\_addresses but that shows all interfaces and I just want eth0. Assuming that list is eth0, eth1, etc. etc. then I guess I could just take the first item in the list.

---

<div class="post-metadata">

**Author:** ![Raj\_Desikavinayagomp](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@Raj\_Desikavinayagomp](https://forum.ansible.com/u/Raj_Desikavinayagomp)\
**Post date:** [April 29, 2015, 8:37pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/4 "2015-04-29T20:37:20Z")

</div>

Not a straight way but a roundabout way

ansible -i inventory host\_group -m setup -a filter=“ansible\_eth0”|grep -A1 ipv4|tail -1|cut -d: -f2|cut -d""" -f2

Need to check if there are different ways to extract it.

---

<div class="post-metadata">

**Author:** ![Igor\_I](https://avatars.discourse-cdn.com/v4/letter/i/e68b1a/32.png) [@Igor\_I](https://forum.ansible.com/u/Igor_I)\
**Post date:** [July 5, 2016, 8:20am UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/5 "2016-07-05T08:20:33Z")

</div>

$ ansible -i inventory -m setup -a “filter=facter\_ipaddress\_eth1” [hostname.example.org](http://hostname.example.org)

`

[hostname.example.org](http://hostname.example.org) | SUCCESS =\> {  
“ansible\_facts”: {  
“facter\_ipaddress\_eth1”: “192.168.33.10”  
},  
“changed”: false  
}

`

---

<div class="post-metadata">

**Author:** ![Agusti\_Tomas](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Agusti\_Tomas](https://forum.ansible.com/u/Agusti_Tomas)\
**Post date:** [August 18, 2016, 3:16pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/6 "2016-08-18T15:16:21Z")

</div>

Igor, I’ve been googling a bit and can’t find what the difference between facter\_ipaddress\_eth1 and ansible\_eth0.ipv4.address is. Could you please clarify?

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [August 19, 2016, 9:41am UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/7 "2016-08-19T09:41:17Z")

</div>

If facter (a Puppet utility) is installed on the node, ansible picks  
up those facts along with its own.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [August 19, 2016, 9:48am UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/8 "2016-08-19T09:48:35Z")

</div>

If facter (a Puppet utility) is installed on the node, ansible picks  
up those facts along with its own.

---

<div class="post-metadata">

**Author:** ![Agusti\_Tomas](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Agusti\_Tomas](https://forum.ansible.com/u/Agusti_Tomas)\
**Post date:** [August 19, 2016, 10:13am UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/9 "2016-08-19T10:13:20Z")

</div>

Thanks Dick, looks like I’ll have to install facter on my CentOS box.

---

<div class="post-metadata">

**Author:** ![Werner\_Flamme](https://avatars.discourse-cdn.com/v4/letter/w/c68b51/32.png) [@Werner\_Flamme](https://forum.ansible.com/u/Werner_Flamme)\
**Post date:** [August 19, 2016, 10:56am UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/10 "2016-08-19T10:56:22Z")

</div>

The difference might be a non-existing interface 😉

facter is requested to show the address of interface "eth1" while  
ansible should show the address of "eth0".

D&r  
Werner

Agusti Tomas [18.08.2016 17:16]:

---

<div class="post-metadata">

**Author:** ![Agusti\_Tomas](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Agusti\_Tomas](https://forum.ansible.com/u/Agusti_Tomas)\
**Post date:** [August 19, 2016, 12:13pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/11 "2016-08-19T12:13:35Z")

</div>

Werner,

Yes, that was a typo, but if it would have been ansible\_eth1.ipv4.address, would the expressions have been equivalent?

---

<div class="post-metadata">

**Author:** ![Werner\_Flamme](https://avatars.discourse-cdn.com/v4/letter/w/c68b51/32.png) [@Werner\_Flamme](https://forum.ansible.com/u/Werner_Flamme)\
**Post date:** [August 19, 2016, 12:52pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/12 "2016-08-19T12:52:09Z")

</div>

Agusti Tomas [19.08.2016 14:13]:

> Werner,
> 
> Yes, that was a typo, but if it would have been ansible\_eth1.ipv4.address,  
> would the expressions have been equivalent?

Unfortunately not:

# ansible me -m setup -a "filter=facter\_ipaddress\_eth1"  
localhost | SUCCESS =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"ansible\_facts": {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"facter\_ipaddress\_eth1": "141.65.x.y"  
&nbsp;&nbsp;&nbsp;&nbsp;},  
&nbsp;&nbsp;&nbsp;&nbsp;"changed": false  
}

ansible me -m setup -a "filter=ansible\_eth1.ipv4.address"  
localhost | SUCCESS =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"ansible\_facts": {},  
&nbsp;&nbsp;&nbsp;&nbsp;"changed": false  
}

I get a (lengthy) result for  
# ansible me -m setup -a "filter=ansible\_eth1"  
but I don't get a result for  
# ansible me -m setup -a "filter=ansible\_eth1.ipv4"  
# ansible me -m setup -a "filter=ansible\_eth1.ipv4"  
# ansible me -m setup -a "filter=ansible\_eth1[ipv4]"  
# ansible me -m setup -a "filter=ansible\_eth1['ipv4']"

Werner

---

<div class="post-metadata">

**Author:** ![Agusti\_Tomas](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Agusti\_Tomas](https://forum.ansible.com/u/Agusti_Tomas)\
**Post date:** [August 19, 2016, 12:54pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/13 "2016-08-19T12:54:26Z")

</div>

Alright, thanks. I better get facter to work then.

---

<div class="post-metadata">

**Author:** ![Werner\_Flamme](https://avatars.discourse-cdn.com/v4/letter/w/c68b51/32.png) [@Werner\_Flamme](https://forum.ansible.com/u/Werner_Flamme)\
**Post date:** [August 19, 2016, 1:05pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/14 "2016-08-19T13:05:10Z")

</div>

Waaah, reading the docs might make that clear:

2nd note on \<[http://docs.ansible.com/ansible/setup\_module.html&gt;:](http://docs.ansible.com/ansible/setup_module.html&gt;:)

The filter option filters only the first level subkey below ansible\_facts.

And since the first level subkey is "ansible\_eth1", the filter does not  
look deeper.

Facter's most facts are not nested (except for e.g. facter\_os), so this  
works better in the given case.

Werner

Agusti Tomas [19.08.2016 14:54]:

---

<div class="post-metadata">

**Author:** ![Agusti\_Tomas](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Agusti\_Tomas](https://forum.ansible.com/u/Agusti_Tomas)\
**Post date:** [August 19, 2016, 1:08pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/15 "2016-08-19T13:08:03Z")

</div>

I got facter to install via playbook now on my CentOS 7 box and the first time it runs the playbook it doesn’t find the facter\_ipaddress\_eth1 but it does find it the second time I run the playbook. Do you know if there should be some waiting time after installing facter?

---

<div class="post-metadata">

**Author:** ![Werner\_Flamme](https://avatars.discourse-cdn.com/v4/letter/w/c68b51/32.png) [@Werner\_Flamme](https://forum.ansible.com/u/Werner_Flamme)\
**Post date:** [August 19, 2016, 1:26pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/16 "2016-08-19T13:26:24Z")

</div>

I am not aware of an after-installation pause. Do you use some cache for  
facts, like redis?

There may be a timeout during the collection of facts, as I can see at  
my box (not Centos, but SLES), the runtime is either short or quite long  
- maybe some facts are hard to detect.

Agusti Tomas [19.08.2016 15:08]:

---

<div class="post-metadata">

**Author:** ![Agusti\_Tomas](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Agusti\_Tomas](https://forum.ansible.com/u/Agusti_Tomas)\
**Post date:** [August 19, 2016, 1:39pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/17 "2016-08-19T13:39:25Z")

</div>

Nothing complicated, facter\_ipaddress\_eth1.

Actually I have this in my playbook:

- name: Check facter  
command: “facter ipaddress\_eth1”  
register: result

- debug:  
var: result

And it prints the right result:

==\> buildmaster: TASK [common : install facter] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
==\> buildmaster: ok: [127.0.0.1]  
==\> buildmaster:  
==\> buildmaster: TASK [common : Check facter] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
==\> buildmaster: changed: [127.0.0.1]  
==\> buildmaster:  
==\> buildmaster: TASK [common : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
==\> buildmaster: ok: [127.0.0.1] =\> {  
==\> buildmaster: “result”: {  
==\> buildmaster: “changed”: true,  
==\> buildmaster: “cmd”: [  
==\> buildmaster: “facter”,  
==\> buildmaster: “ipaddress\_eth1”  
==\> buildmaster: ],  
==\> buildmaster: “delta”: “0:00:01.062820”,  
==\> buildmaster: “end”: “2016-08-19 13:38:14.678980”,  
==\> buildmaster: “rc”: 0,  
==\> buildmaster: “start”: “2016-08-19 13:38:13.616160”,  
==\> buildmaster: “stderr”: “”,  
==\> buildmaster: “stdout”: “192.168.20.200”,  
==\> buildmaster: “stdout\_lines”: [  
==\> buildmaster: “192.168.20.200”  
==\> buildmaster: ],  
==\> buildmaster: “warnings”:   
==\> buildmaster: }  
==\> buildmaster: }

Real funny stuff going on here.

---

<div class="post-metadata">

**Author:** ![Agusti\_Tomas](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Agusti\_Tomas](https://forum.ansible.com/u/Agusti_Tomas)\
**Post date:** [August 19, 2016, 1:40pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/18 "2016-08-19T13:40:17Z")

</div>

Forgot to mention I run Check facter just after this:

- name: install facter  
yum:  
name: facter  
state: latest

So no much time to gather facts.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 19, 2016, 1:53pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/19 "2016-08-19T13:53:21Z")

</div>

Just run gather facts after you installed facter like this

- setup:

---

<div class="post-metadata">

**Author:** ![Agusti\_Tomas](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Agusti\_Tomas](https://forum.ansible.com/u/Agusti_Tomas)\
**Post date:** [August 19, 2016, 1:57pm UTC](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129/20 "2016-08-19T13:57:10Z")

</div>

Thanks Kai, however I didn’t fully catch that. You mean

**- name: install facter**  
**yum:**  
**name: facter**  
**state: latest**

**- setup:**

**Like this?**

[Next page](https://forum.ansible.com/t/m-setup-a-filter-ansible-eth0-ipv4-address-returns-no-results/18129.md?page=2)
