Setup module to retrieve only ipv4

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:

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

am I missing something?
When I check the full yaml for ansible_facts and parse it with

when I use

Setup module filter works only for top level elements.

So closest you could get is:

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

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

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

Wow this is not very easy to figure out :slight_smile:

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

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 }}