Neat new feature for the debug module on 1.4 (devel)

179 views
Skip to first unread message

Michael DeHaan

unread,
Oct 14, 2013, 9:10:50 PM10/14/13
to ansible...@googlegroups.com
I just pushed a feature to 1.4 that makes debugging things much more fun and exciting.   In particular I'm happy for this as I've wanted this about 5 times in the last 5 days :)

You used to be able to do this, but it was kind of messy and had to quote it:

- debug: msg="the value of variable is {{ variable }}"

This would not pretty print things and would output things all in one line, if you were lucky.  It also tended to not work with some things.

For instance, in 1.4, you can now do this:

   - shell: uptime
     register: foo

   - debug: var=foo

Much cleaner!   It will then pretty-print the resultant variable, which is great for big data structures.
And it will show you exactly what that particular host would see at it's point in the host loop.

It takes both Python and Jinja2 formats, so you can do things like

 - debug: var=hostvars[inventory_hostname]

That will print *ALL* of the variables in scope for that particular host.  Yep, all of them.

Similarly:

 - debug: var=hostvars[inventory_hostname].ansible_default_ipv4

That will print just the default ipv4 interface info 

Currently msg and var are mutually exclusive, and it's only one variable to debug per task.

If you try to debug things that aren't valid variables, it will also be nice and tell you what the error was, but won't explode.

Upgrades are quite welcome if people have ideas.

(Docs for this will appear in the next docs push)


--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Peter Gehres

unread,
Oct 14, 2013, 11:47:24 PM10/14/13
to ansible...@googlegroups.com
Thank you! I am so excited for this!


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Peter Gehres
Site Reliability Engineer | AppDynamics, Inc.
Reply all
Reply to author
Forward
0 new messages