# Error While nesting the with\_item

**URL:** <https://forum.ansible.com/t/error-while-nesting-the-with-item/27747>\
**Category:** Ansible Project\
**Created:** [June 8, 2018, 11:37am UTC](https://forum.ansible.com/t/error-while-nesting-the-with-item/27747 "2018-06-08T11:37:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![devopsram2012](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@devopsram2012](https://forum.ansible.com/u/devopsram2012)\
**Post date:** [June 8, 2018, 11:37am UTC](https://forum.ansible.com/t/error-while-nesting-the-with-item/27747/1 "2018-06-08T11:37:28Z")

</div>

Dear All,  
I want to get output message of the log using ansible debug .  
[Case-1]  
If I know the no of results and I want too print then I can use below code  
CODE[start]

- name: Display all Endpoints Health\_Check test results[--------]  
debug:  
msg:
- " endpoint check - [{{ ansible\_fqdn }}] - [status\_code: {{ PCheck.results[0].status }}] - {{ PCheck.results[0].url }}"
- " endpoint check - [{{ ansible\_fqdn }}] - [status\_code: {{ PCheck.results[1].status }}] - {{ PCheck.results[1].url }}"
- " endpoint check - [{{ ansible\_fqdn }}] - [status\_code: {{ PCheck.results[2].status }}] - {{ PCheck.results[2].url }}"

[Case-2]  
If I don’t know about the number of results ,because I’m taking data from a file then I don’t know the no of entry so output result will be a variable value  
Then how the above code will look like ,please suggest  
CODE[start]

- name: Display all Endpoints Health\_Check test results[--------]  
debug:  
msg:
- " endpoint check - [{{ ansible\_fqdn }}] - [status\_code: {{ PCheck.results[0].status }}] - {{ PCheck.results[0].url }}"
- " endpoint check - [{{ ansible\_fqdn }}] - [status\_code: {{ PCheck.results[0+1].status }}] - {{ PCheck.results[0+1].url }}"
- " endpoint check - [{{ ansible\_fqdn }}] - [status\_code: {{ PCheck.results[0+2].status }}] - {{ PCheck.results[0+2].url }}"  
.  
.  
.
- " endpoint check - [{{ ansible\_fqdn }}] - [status\_code: {{ PCheck.results[0+n].status }}] - {{ PCheck.results[0+n].url }}"

NOTE: here ‘n’ is the no of entries in file

Please suggest . I’m new in Ansible world.

Thanks & Regards  
Ram

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [June 8, 2018, 12:26pm UTC](https://forum.ansible.com/t/error-while-nesting-the-with-item/27747/2 "2018-06-08T12:26:50Z")

</div>

Investigate loop: and with\_items:

- name: Display all Endpoints Health\_Check test results  
debug:  
msg: “endpoint check - [{{ ansible\_fqdn }}] - [status\_code: {{ item.status }}] - {{ item.url }}”  
with\_items: {{ PCheck.results }}

​Untested - something like that, anyway. In the loop “item” is the current element of the list passed to with\_items:.​

​Regards, K.  
​

---

<div class="post-metadata">

**Author:** ![devopsram2012](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@devopsram2012](https://forum.ansible.com/u/devopsram2012)\
**Post date:** [June 9, 2018, 12:34pm UTC](https://forum.ansible.com/t/error-while-nesting-the-with-item/27747/3 "2018-06-09T12:34:51Z")

</div>

Thanks Karl Auer for fast reply.  
It worked for me .

Thanks & Regards  
Ram

---

<div class="post-metadata">

**Author:** ![devopsram2012](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@devopsram2012](https://forum.ansible.com/u/devopsram2012)\
**Post date:** [June 9, 2018, 12:35pm UTC](https://forum.ansible.com/t/error-while-nesting-the-with-item/27747/4 "2018-06-09T12:35:51Z")

</div>

Thanks Karl Auer for fast reply.  
It worked for me.

Thanks & Regards  
Ram
