# Setup module to retrieve only ipv4

**URL:** <https://forum.ansible.com/t/setup-module-to-retrieve-only-ipv4/40584>\
**Category:** Get Help\
**Created:** [February 24, 2025, 9:17am UTC](https://forum.ansible.com/t/setup-module-to-retrieve-only-ipv4/40584 "2025-02-24T09:17:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://forum.ansible.com/u/eliassal)\
**Post date:** [February 24, 2025, 9:17am UTC](https://forum.ansible.com/t/setup-module-to-retrieve-only-ipv4/40584/1 "2025-02-24T09:17:13Z")

</div>

Hi, I am trying the following

`ansible localhost -m ansible.builtin.setup -a 'filter=ansible_facts.ansible_eth0.ipv4.address'`

also  
`ansible localhost -m ansible.builtin.setup -a 'filter=ansible_eth0.ipv4.address'`  
also  
`ansible localhost -m ansible.builtin.setup -a 'filter=ipv4.address'`

but noting is returned as follows:

```auto
localhost | SUCCESS => {
    "ansible_facts": {},
    "changed": false
}

```

am I missing something?  
When I check the full yaml for ansible\_facts and parse it with

 ![image](https://us1.discourse-cdn.com/ansible/original/2X/3/3f1e47c4babf581f7cdc7491a99b93e936dd1c7b.png)

when I use

 ![image](https://us1.discourse-cdn.com/ansible/original/2X/d/d64dae262508ba32e004112f356d2aceb2a96efa.png)

---

<div class="post-metadata">

**Author:** ![kristianheljas](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kristianheljas/32/7702_2.png) [@kristianheljas](https://forum.ansible.com/u/kristianheljas)\
**Post date:** [February 24, 2025, 1:23pm UTC](https://forum.ansible.com/t/setup-module-to-retrieve-only-ipv4/40584/2 "2025-02-24T13:23:40Z")

</div>

Setup module filter works only for top level elements.

So closest you could get is:

```auto
ansible localhost -m ansible.builtin.setup -a 'filter=ansible_eth0'

```

If you want more consice output, consider using `ip` utility with shell module

```auto
ansible localhost -m shell -a "ip -f inet addr show eth0 | sed -En -e 's/.*inet ([0-9.]+).*/\1/p'"

```

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://forum.ansible.com/u/eliassal)\
**Post date:** [February 24, 2025, 2:17pm UTC](https://forum.ansible.com/t/setup-module-to-retrieve-only-ipv4/40584/3 "2025-02-24T14:17:42Z")

</div>

Wow this is not very easy to figure out 🙂

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://forum.ansible.com/u/eliassal)\
**Post date:** [February 25, 2025, 8:52am UTC](https://forum.ansible.com/t/setup-module-to-retrieve-only-ipv4/40584/4 "2025-02-25T08:52:01Z")

</div>

Hi kristian, so if we need to access the details in one of the top level elements in a playbook, how this can be done? Thanks

---

<div class="post-metadata">

**Author:** ![kristianheljas](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kristianheljas/32/7702_2.png) [@kristianheljas](https://forum.ansible.com/u/kristianheljas)\
**Post date:** [February 25, 2025, 2:31pm UTC](https://forum.ansible.com/t/setup-module-to-retrieve-only-ipv4/40584/5 "2025-02-25T14:31:12Z")

</div>

Not really sure what you mean.  
I was talking about filter argument for the setup module.

If you are looking to get the ip address, then you can easily use such variable notation as you tried before: `{{ ansible_eth0.ipv4.address }}`
