# Ansible facts in a Jinja template

**URL:** <https://forum.ansible.com/t/ansible-facts-in-a-jinja-template/34366>\
**Category:** Ansible Project\
**Created:** [December 22, 2020, 9:38pm UTC](https://forum.ansible.com/t/ansible-facts-in-a-jinja-template/34366 "2020-12-22T21:38:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [December 22, 2020, 9:38pm UTC](https://forum.ansible.com/t/ansible-facts-in-a-jinja-template/34366/1 "2020-12-22T21:38:51Z")

</div>

I have a playbook that has “gather\_facts: yes”, and with that I’m trying to look through all of the hosts in the playbook and print out the OS version information. The Jinja2 template I’m using is below. The issue I’m having is that it prints the same version information for every host. How can I grab the facts gathered for each host in the play?

Thanks,  
Harry

Operating System Versions report

Date generated: {{ ansible\_date\_time.month }}/{{ ansible\_date\_time.day }}/{{ ansible\_date\_time.year }} {{ ansible\_date\_time.time }}

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [December 22, 2020, 10:07pm UTC](https://forum.ansible.com/t/ansible-facts-in-a-jinja-template/34366/2 "2020-12-22T22:07:38Z")

</div>

Use hostvars. For example  
[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_vars\_facts.html#information-about-ansible-magic-variables](https://docs.ansible.com/ansible/latest/user_guide/playbooks_vars_facts.html#information-about-ansible-magic-variables)

{% for i in ansible\_play\_batch | sort %}  
Host: {{ i }}  
Distribution: {{ hostvars[i]['ansible\_distribution'] }}  
&nbsp;&nbsp;&nbsp;&nbsp;...  
{% endfor %}

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [December 23, 2020, 12:57pm UTC](https://forum.ansible.com/t/ansible-facts-in-a-jinja-template/34366/3 "2020-12-23T12:57:08Z")

</div>

Worked perfectly!!! Thank you very much!

Harry
