# usage of loop (with\_items), register and debug

**URL:** <https://forum.ansible.com/t/usage-of-loop-with-items-register-and-debug/24205>\
**Category:** Ansible Developer\
**Created:** [April 12, 2017, 4:42pm UTC](https://forum.ansible.com/t/usage-of-loop-with-items-register-and-debug/24205 "2017-04-12T16:42:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravi\_katta](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@ravi\_katta](https://forum.ansible.com/u/ravi_katta)\
**Post date:** [April 12, 2017, 4:42pm UTC](https://forum.ansible.com/t/usage-of-loop-with-items-register-and-debug/24205/1 "2017-04-12T16:42:24Z")

</div>

Hello, checking if anyone have any insight or pointing me to a solution, about using loops with register and debug:  
I’m looking for  
a) just debug msg output whenever the mountpoint on remote server is not configured.  
b) lesser debug output whenever the mountpoint is not configured, as currently with\_items: ‘{{ mount\_stat.results }}’ is spitting all the output from the command when the mountpoint is not configured

Not sure

— #

- name : test  
hosts: lab1  
any\_errors\_fatal: true  
gather\_facts: false  
ignore\_errors: true

tasks:

- name: check mount point {{ item }}  
tags: art  
command: “mountpoint {{ item }}”  
with\_items:

- /opt/mqmm

- /var/mqm

- /var/mqm/errors

- /var/mqm/logs

- /var/mqm/trace  
register: mount\_stat

- debug:  
msg: ‘The command ({{ item.cmd }}) did not have a 0 return code’  
when: item.rc != 0  
with\_items: ‘{{ mount\_stat.results }}’

Here is the example from ansible docs, but i’m not able to get that converted/translated to my requirement  
— #

- name :test  
hosts: lab1  
gather\_facts: false  
ignore\_errors: true

tasks:

- shell: “echo {{ item }}”  
with\_items:

- “one”

- “two”  
register: echo

- debug:  
msg: ‘The command ({{ item.cmd }}) did not have a 0 return code’  
when: item.rc == 0  
with\_items: ‘{{ echo.results }}’

---

<div class="post-metadata">

**Author:** ![ravi\_katta](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@ravi\_katta](https://forum.ansible.com/u/ravi_katta)\
**Post date:** [April 13, 2017, 1:58pm UTC](https://forum.ansible.com/t/usage-of-loop-with-items-register-and-debug/24205/2 "2017-04-13T13:58:35Z")

</div>

I think I have figured it out after googling:

debug: var=item.stderr  
when: item.rc != 0  
with\_items: “{{ mount\_stat.results }}”
