I'd like to filter the JSON output of ad-hoc ansible commands - e.g. grab the long list of "facts" for multiple hosts, and show only one that could be several levels deep, such as ansible_lsb.description
, so I can quickly compare what versions of software they're running, check accurate times or timezones, whatever.
This works:
ansible myserver -m setup -a 'filter=ansible_lsb'
myserver | SUCCESS => {
"ansible_facts": {
"ansible_lsb": {
"codename": "wheezy",
"description": "Debian GNU/Linux 7.11 (wheezy)",
"id": "Debian",
"major_release": "7",
"release": "7.11"
}
},
"changed": false
}
However, as the setup module docs state, "the filter option filters only the first level subkey below ansible_facts", so this fails:
ansible myserver -m setup -a 'filter=ansible_lsb.description'
myserver | SUCCESS => {
"ansible_facts": {},
"changed": false
}
(though for reference, you can use dot notation in other places such as a task's when conditional)
Is there a way to filter the JSON keys before the output is displayed?