Setup module filter question

Hello, everyone.

I’m trying to get ipv4 facts returned via the command line, so I run “ansible myhost -m setup -a filter=”" ". . If I run ansible myhost -m setup -a filter=“ansible_eth*”, I get:

myhost | SUCCESS => {
“ansible_facts”: {
“ansible_eth0”: {
“active”: true,
“device”: “eth0”,
“features”: {},
“ipv4”: {
“address”: “69.x.x.24”,
“broadcast”: “69.x.x.255”,
“netmask”: “255.255.252.0”,
“network”: “69.x.x.0”
},
“ipv4_secondaries”: [
{
“address”: “69.x.x.101”,
“broadcast”: “69.x.x.255”,
“netmask”: “255.255.252.0”,
“network”: “69.x.x.0”
}
],
“ipv6”: [
{
“address”: “fe80::”,
“prefix”: “64”,
“scope”: “link”
}
],
“macaddress”: “00:00:00:00:00:00”,
“module”: “vmxnet”,
“mtu”: 1500,
“pciid”: “0000:02:00.0”,
“promisc”: false,
“speed”: 1000,
“type”: “ether”
},

The filter functionality of the setup module only works for top level keys.

To get more advanced filtering, you’ll need a playbook, and to use jinja to get what you are wanting.

Thanks, Matt.

Hello,
As the filter option filters only the first level key of ansible_facts.

if you want to get it by adhoc command only then you can try this command to get a bit similar result:

ansible myhost -m setup -a filter=“ansible_default_ipv4”