# print template variable

**URL:** <https://forum.ansible.com/t/print-template-variable/18004>\
**Category:** Ansible Project\
**Created:** [April 17, 2015, 10:59am UTC](https://forum.ansible.com/t/print-template-variable/18004 "2015-04-17T10:59:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Paine](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tom\_Paine](https://forum.ansible.com/u/Tom_Paine)\
**Post date:** [April 17, 2015, 10:59am UTC](https://forum.ansible.com/t/print-template-variable/18004/1 "2015-04-17T10:59:13Z")

</div>

Trying to debug a template and want to display the data for a variable.

How can I do that from inside a template?

{% for foo in bar %}  
\<print foo to stdout?\>  
{% endfor %}

---

<div class="post-metadata">

**Author:** ![Tom\_Paine](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tom\_Paine](https://forum.ansible.com/u/Tom_Paine)\
**Post date:** [April 17, 2015, 11:19am UTC](https://forum.ansible.com/t/print-template-variable/18004/2 "2015-04-17T11:19:09Z")

</div>

> Trying to work out why this works:

TASK: [debug var=groups.security\_group\_app] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Friday 17 April 2015 12:15:01 +0100 (0:00:00.301) 0:00:13.586 \*\*\*\*\*\*\*\*\*\*  
ok: [52.17.198.95] =\> {  
“var”: {  
“groups.security\_group\_app”: [  
“52.xx.xx.xx”,  
“52.xx.xx.xx”  
]  
}  
}

But this doesn’t:

{% for ec2\_host\_ip in groups.security\_group\_app %}  
{{ ec2\_host\_ip|pprint }}  
{% endfor %}

fatal: [52.xx.xx.xx] =\> {‘msg’: “AnsibleUndefinedVariable: One or more undefined variables: ansible.runner.HostVars object has no element [u’52.xx.xx.xx’, u’52.xx.xx.xx’]”, ‘failed’: True}

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 17, 2015, 2:21pm UTC](https://forum.ansible.com/t/print-template-variable/18004/3 "2015-04-17T14:21:02Z")

</div>

you can do this:

{% for ec2\_host\_ip in groups.security\_group\_app %}  
&nbsp;&nbsp;{{ ec2\_host\_ip}}  
{% endfor %}

or

{{ groups.security\_group\_app|pprint}}

the combination of both does not make sense.

---

<div class="post-metadata">

**Author:** ![Tom\_Paine](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tom\_Paine](https://forum.ansible.com/u/Tom_Paine)\
**Post date:** [April 17, 2015, 2:32pm UTC](https://forum.ansible.com/t/print-template-variable/18004/4 "2015-04-17T14:32:56Z")

</div>

Can it be displayed on the playbook output? I’d prefer not to have to go and check the template each run during debug.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 17, 2015, 2:40pm UTC](https://forum.ansible.com/t/print-template-variable/18004/5 "2015-04-17T14:40:44Z")

</div>

then you don't want a template, use the debug: module.

---

<div class="post-metadata">

**Author:** ![Tom\_Paine](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tom\_Paine](https://forum.ansible.com/u/Tom_Paine)\
**Post date:** [April 20, 2015, 10:54am UTC](https://forum.ansible.com/t/print-template-variable/18004/6 "2015-04-20T10:54:08Z")

</div>

I’m aware of the debug module, but I need to debug a temporary template variable.

Is the answer that it cannot be ‘printed’ to the console and you have to just watch the file?

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [May 17, 2015, 9:34am UTC](https://forum.ansible.com/t/print-template-variable/18004/7 "2015-05-17T09:34:23Z")

</div>

If I recall correctly, the --diff flag might come in handy in your case.
