print template variable

162 views
Skip to first unread message

ddffgpmfn

unread,
Apr 17, 2015, 6:59:14 AM4/17/15
to ansible...@googlegroups.com
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 %}

ddffgpmfn

unread,
Apr 17, 2015, 7:19:09 AM4/17/15
to ansible...@googlegroups.com
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}

Brian Coca

unread,
Apr 17, 2015, 10:21:05 AM4/17/15
to ansible...@googlegroups.com
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.




--
Brian Coca

ddffgpmfn

unread,
Apr 17, 2015, 10:32:56 AM4/17/15
to ansible...@googlegroups.com
Can it be displayed on the playbook output? I'd prefer not to have to go and check the template each run during debug.

Brian Coca

unread,
Apr 17, 2015, 10:40:47 AM4/17/15
to ansible...@googlegroups.com
then you don't want a template, use the debug: module.



--
Brian Coca

ddffgpmfn

unread,
Apr 20, 2015, 6:54:08 AM4/20/15
to ansible...@googlegroups.com
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?

Dan Vaida

unread,
May 17, 2015, 5:34:23 AM5/17/15
to ansible...@googlegroups.com
If I recall correctly, the --diff flag might come in handy in your case.
Reply all
Reply to author
Forward
0 new messages