Ansible facts from command line - drill down

Running this from command link - ansible all -m setup -a ‘filter=ansible_default_ipv4*’

The output is

127.0.0.1 | SUCCESS => {

“ansible_facts”: {

“ansible_default_ipv4”: {

“address”: “192.168.150.129”,

“alias”: “eno16777736”,

“broadcast”: “192.168.150.255”,

“gateway”: “192.168.150.2”,

“interface”: “eno16777736”,

“macaddress”: “00:0c:29:23:6d:31”,

“mtu”: 1500,

“netmask”: “255.255.255.0”,

“network”: “192.168.150.0”,

“type”: “ether”

}

},

“changed”: false

}

Trying to drill down to just display the address portion, and it is not displaying. ansible all -m setup -a ‘filter=ansible_default_ipv4_address’ or ansible all -m setup -a ‘filter=ansible_default_ipv4.address’ does not display the address fact.

Do I have to do a grep on it or can I drill all the way down to address using the inbuilt ansible setup command? I know I can run this and it works → [ansible@localhost exercises]$ ansible all -m setup -a ‘filter=ansible_default_ipv4*’ | grep address

The filter functionality only works for top level keys. You can either grep, or use the --tree option to write the response out to a file, and then use something like jq or a programming language to parse the JSON file.