# loop after loop conditional

**URL:** <https://forum.ansible.com/t/loop-after-loop-conditional/32989>\
**Category:** Ansible Project\
**Created:** [May 20, 2020, 7:21pm UTC](https://forum.ansible.com/t/loop-after-loop-conditional/32989 "2020-05-20T19:21:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jer8jer](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jer8jer](https://forum.ansible.com/u/jer8jer)\
**Post date:** [May 20, 2020, 7:21pm UTC](https://forum.ansible.com/t/loop-after-loop-conditional/32989/1 "2020-05-20T19:21:31Z")

</div>

Trying to check if a user exists locally and if true, check to see if it has sudo rights. I can’t seem to process the second loop. I tried using out.results.item but error:

fatal: [hostname]: FAILED! =\> {“msg”: “‘list object’ has no attribute ‘item’”}

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 20, 2020, 7:48pm UTC](https://forum.ansible.com/t/loop-after-loop-conditional/32989/2 "2020-05-20T19:48:55Z")

</div>

You forgot the output.

Also, what is your high level goal.  
Why do you need to know if a user exists and has sudo permission.

---

<div class="post-metadata">

**Author:** ![jer8jer](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jer8jer](https://forum.ansible.com/u/jer8jer)\
**Post date:** [May 20, 2020, 7:58pm UTC](https://forum.ansible.com/t/loop-after-loop-conditional/32989/3 "2020-05-20T19:58:07Z")

</div>

My bigger question is how to run a loop with with\_items then process the output in the second play.

The objective is to see if user1, user2, user3 exist locally make sure they have sudo rights.

when my play tries to process out.results.item:

- name: check if existing user is in sudoers  
command: grep {{ item }} /etc/sudoers  
with\_items: “{{ out.results.item }}”  
register: message

TASK [check if existing user is in sudoers] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [hostname]: FAILED! =\> {“msg”: “‘list object’ has no attribute ‘item’”}  
to retry, use: --limit @/opt/rhel-ansible/check\_sudo\_users.retry

---

<div class="post-metadata">

**Author:** ![jer8jer](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jer8jer](https://forum.ansible.com/u/jer8jer)\
**Post date:** [May 20, 2020, 7:59pm UTC](https://forum.ansible.com/t/loop-after-loop-conditional/32989/4 "2020-05-20T19:59:42Z")

</div>

If I leave the playbook like this:

- name: check if existing user is in sudoers  
command: grep {{ item }} /etc/sudoers  
with\_items: “{{ out.results }}”  
register: message

it attempts to run a grep on all output from out.results.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 20, 2020, 10:02pm UTC](https://forum.ansible.com/t/loop-after-loop-conditional/32989/5 "2020-05-20T22:02:09Z")

</div>

> My bigger question is how to run a loop with with\_items then process the output in the second play.
> 
> The objective is to see if user1, user2, user3 exist locally make sure they have sudo rights.

See  
[https://docs.ansible.com/ansible/latest/modules/user\_module.html](https://docs.ansible.com/ansible/latest/modules/user_module.html)

---

<div class="post-metadata">

**Author:** ![jer8jer](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jer8jer](https://forum.ansible.com/u/jer8jer)\
**Post date:** [May 20, 2020, 11:43pm UTC](https://forum.ansible.com/t/loop-after-loop-conditional/32989/6 "2020-05-20T23:43:31Z")

</div>

This almost works but I cant make it skip when the grep root /etc/password fails. I dont understand how to access out.rc when using a loop. My when statement doesnt work. I am not as interested in this task as I am pulling rc from a loop then using it in the next loop.
