# How To Filter Ansible Facts In Template And Playbook

**URL:** <https://forum.ansible.com/t/how-to-filter-ansible-facts-in-template-and-playbook/35562>\
**Category:** Ansible Project\
**Created:** [July 28, 2021, 6:22pm UTC](https://forum.ansible.com/t/how-to-filter-ansible-facts-in-template-and-playbook/35562 "2021-07-28T18:22:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isaiah\_Banks](https://avatars.discourse-cdn.com/v4/letter/i/f1d935/32.png) [@Isaiah\_Banks](https://forum.ansible.com/u/Isaiah_Banks)\
**Post date:** [July 28, 2021, 6:22pm UTC](https://forum.ansible.com/t/how-to-filter-ansible-facts-in-template-and-playbook/35562/1 "2021-07-28T18:22:44Z")

</div>

Hello. I am new to Ansible. I am trying to figure out how I can filter a list of ansible\_facts in a template and playbook and get the information I directly need. I am trying to do this with json\_query() plugin.

However, when I pass the ansible facts to the json\_query() plugin in the playbook, it automatically strips out the keys. I am doing it like this:

- name: Filter ansible facts  
debug:  
msg: “{{ ansible\_facts | json\_query(‘\*’) }}”

This example is just so I can see what the plugin would return. I want to be able to query against the keys, then after that return the value of that key.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [July 29, 2021, 3:51am UTC](https://forum.ansible.com/t/how-to-filter-ansible-facts-in-template-and-playbook/35562/2 "2021-07-29T03:51:20Z")

</div>

What are you looking for exactly?

---

<div class="post-metadata">

**Author:** ![Pushparaj\_Gothandam](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pushparaj_gothandam/32/5538_2.png) [@Pushparaj\_Gothandam](https://forum.ansible.com/u/Pushparaj_Gothandam)\
**Post date:** [July 29, 2021, 1:19pm UTC](https://forum.ansible.com/t/how-to-filter-ansible-facts-in-template-and-playbook/35562/3 "2021-07-29T13:19:49Z")

</div>

You can call them directly in your playbook
