Ansible facts from command line - drill down

33 views
Skip to first unread message

Anfield

unread,
Aug 23, 2017, 3:02:57 PM8/23/17
to Ansible Project
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

Matt Martz

unread,
Aug 23, 2017, 3:35:50 PM8/23/17
to ansible...@googlegroups.com
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ecebca32-cfd6-4579-a49f-1438774352fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages