debugging a loop

2,425 views
Skip to first unread message

Michael Baydoun

unread,
Sep 30, 2013, 2:25:17 PM9/30/13
to ansible...@googlegroups.com
How can I debug each iteration of a loop in a playbook?
For example

---
- hosts: localhost
gather_facts: no
vars:
dns_server:
4.4.4.4
8.8.8.8
tasks:
- name: query server
shell: dig @{{ dns_server }} google.com
with_items: $dns_server
ignore_errors: True
register: result
## - debug: msg="{{ result.stdout }}"


what should the debug line look like to display stdout from each dig command?

Michael DeHaan

unread,
Sep 30, 2013, 3:33:57 PM9/30/13
to ansible...@googlegroups.com
First run with "-v" to see what the results array looks like.

Then, for the thing that is a loop, you could do:

- debug: msg={{ item }}
  with_items: foo






--
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.



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

Michael DeHaan

unread,
Sep 30, 2013, 3:41:25 PM9/30/13
to ansible...@googlegroups.com
Incidentally I think I'd like it if the debug module allowed this

debug: var=varname

(no template args) also

This way it would be easier to use on things that weren't neatly key=value and could just dump the datastructure by name.


Brian Coca

unread,
Sep 30, 2013, 3:57:46 PM9/30/13
to ansible...@googlegroups.com
the debug there already does that. itwill run per iteration of the playbook, but not per iteration of the task. result will have an array of the output of the task keyed by item.

you can also use -vvv to get the debug as it happens.

Michael DeHaan

unread,
Sep 30, 2013, 4:22:47 PM9/30/13
to ansible...@googlegroups.com
Right, but it should make the variable name a possible key to make it easier to do this with certain data.

Right now, it's keyed a bit trying to output strings, which causes problems with template evaluation.




On Mon, Sep 30, 2013 at 3:57 PM, Brian Coca <bria...@gmail.com> wrote:
the debug there already does that. itwill run per iteration of the playbook, but not per iteration of the task. result will have an array of the output of the task keyed by item.

you can also use -vvv to get the debug as it happens.

--
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.
Reply all
Reply to author
Forward
0 new messages