# Ansible: Debug and iteration

**URL:** <https://forum.ansible.com/t/ansible-debug-and-iteration/31952>\
**Category:** Ansible Project\
**Created:** [January 13, 2020, 7:22am UTC](https://forum.ansible.com/t/ansible-debug-and-iteration/31952 "2020-01-13T07:22:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jegansignup](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jegansignup](https://forum.ansible.com/u/jegansignup)\
**Post date:** [January 13, 2020, 7:22am UTC](https://forum.ansible.com/t/ansible-debug-and-iteration/31952/1 "2020-01-13T07:22:03Z")

</div>

Hello Team,

I am trying to iteration register value and print that value using debug but I unable to achieve the result which I want to get it. Below is the register value in that I like to get value of “lifecycle\_state” using debug. Could you please someone help me on this.

Playbook part:

- debug: var=“{{ item }}”  
with\_items: result\_1.volume\_attachments

Register result:

ok: [localhost] =\> (item=result\_1.volume\_attachments) =\> {  
“ansible\_loop\_var”: “item”,  
“item”: “result\_1.volume\_attachments”,  
“result\_1.volume\_attachments”: [  
{  
“attachment\_type”: “iscsi”,  
“availability\_domain”: “xxxxxxxxx”,  
“chap\_secret”: null,  
“chap\_username”: null,  
“compartment\_id”: “xxxxxxxxxxx”,  
“device”: null,  
“display\_name”: “xxxxxxxxx”,  
“id”: “xxxxxxxxxxx”,  
“instance\_id”: “xxxxxx”,  
“ipv4”: “xxxxx”,  
“iqn”: “xxxxxxxxxxxx”,  
“is\_pv\_encryption\_in\_transit\_enabled”: false,  
“is\_read\_only”: false,  
“lifecycle\_state”: “ATTACHED”,  
“port”: 3260,  
“time\_created”: “xxxxxxxx”,  
“volume\_id”: “xxxxxxxxxxx”  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [January 13, 2020, 8:14am UTC](https://forum.ansible.com/t/ansible-debug-and-iteration/31952/2 "2020-01-13T08:14:45Z")

</div>

The first 2 lines of the debug output explain what's going on

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ansible\_loop\_var": "item",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"item": "result\_1.volume\_attachments",

The list 'result\_1.volume\_attachments' is not expanded in the 'with\_items'  
statement and is submitted as 'item' to debug. Then the list is expanded  
var="{{ item }}".

To print the 'lifecycle\_state' attribute of the items in the list try

&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: item.lifecycle\_state  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ result\_1.volume\_attachments }}"

Notes:  
\* Use 'loop' instead of with\_\*  
&nbsp;&nbsp;[https://docs.ansible.com/ansible/latest/porting\_guides/porting\_guide\_2.5.html#migrating-from-with-x-to-loop](https://docs.ansible.com/ansible/latest/porting_guides/porting_guide_2.5.html#migrating-from-with-x-to-loop)  
\* Expand the the variable "{{ result\_1.volume\_attachments }}" in the 'loop'  
&nbsp;&nbsp;to iterate the items of the list  
&nbsp;&nbsp;[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_variables.html#using-variables-with-jinja2](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#using-variables-with-jinja2)  
\* In 'debug' the parameter 'var' is expanded by default

HTH,  
&nbsp;&nbsp;-vlado
