print template variable

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 %}

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}

you can do this:

{% for ec2_host_ip in groups.security_group_app %}
  {{ ec2_host_ip}}
{% endfor %}

or

{{ groups.security_group_app|pprint}}

the combination of both does not make sense.

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

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

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?

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