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)