Ansible and jq

Did you ever wonder what is inside ansible facts? But every attempt to run setup module leaves feeling of ‘tl;dr;’. 377 lines of complicated structure.

One way to deal with it is to move to any modern editor with folding function (vim, atom, emacs, etc).

The other way is to use jq.

There is one catch: ansible output contain not only json, there is a chuck of junk at the first line.

My one-liner for this:

ansible -m setup host|sed ‘1c {‘|jq ‘.ansible_facts|keys’

sed replaces first line with ‘{‘ sign which make output a valid json. The rest is jq heaven.

Just look at this:

ansible -m setup host|sed ‘1c {‘|jq \
ansible -m setup host|sed ‘1c {‘|jq \
Like what you read? Give George Shuklin a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.