# debugging a loop

**URL:** <https://forum.ansible.com/t/debugging-a-loop/13581>\
**Category:** Ansible Project\
**Created:** [September 30, 2013, 6:25pm UTC](https://forum.ansible.com/t/debugging-a-loop/13581 "2013-09-30T18:25:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Baydoun](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Michael\_Baydoun](https://forum.ansible.com/u/Michael_Baydoun)\
**Post date:** [September 30, 2013, 6:25pm UTC](https://forum.ansible.com/t/debugging-a-loop/13581/1 "2013-09-30T18:25:17Z")

</div>

How can I debug each iteration of a loop in a playbook?  
For example

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 30, 2013, 7:33pm UTC](https://forum.ansible.com/t/debugging-a-loop/13581/2 "2013-09-30T19:33:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 30, 2013, 7:41pm UTC](https://forum.ansible.com/t/debugging-a-loop/13581/3 "2013-09-30T19:41:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [September 30, 2013, 7:57pm UTC](https://forum.ansible.com/t/debugging-a-loop/13581/4 "2013-09-30T19:57:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 30, 2013, 8:22pm UTC](https://forum.ansible.com/t/debugging-a-loop/13581/5 "2013-09-30T20:22:47Z")

</div>

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.
