Filtering Ansible Facts

Posted on

Hello. This is my first time posting anything to this channel. Hopefully someone can be of some help. I'm trying to figure out the best way to parse ansible facts in a template or playbook and I'm stuck.

I have about a few weeks experience with Ansible so this is quite new. I have been looking at how to use json_query() with jmespath to query and filter out what I want in ansible facts but it's taking quite a while.

For example I have this:

  • name: Whatever
    msg: "{{ ansible_facts | json_query('*') }}"

Now this is just an example but what this is doing is returning a list I believe and it removes the keys. However, I do not want that. I want to be able to run query on the ansible fact keys first. How do I get this done? Thanks in advance.