# Need help with Loop and Stat playbook

**URL:** <https://forum.ansible.com/t/need-help-with-loop-and-stat-playbook/34344>\
**Category:** Ansible Project\
**Created:** [December 16, 2020, 11:09pm UTC](https://forum.ansible.com/t/need-help-with-loop-and-stat-playbook/34344 "2020-12-16T23:09:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thuan1](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@Thuan1](https://forum.ansible.com/u/Thuan1)\
**Post date:** [December 16, 2020, 11:09pm UTC](https://forum.ansible.com/t/need-help-with-loop-and-stat-playbook/34344/1 "2020-12-16T23:09:12Z")

</div>

Hi all,

I’m try to use the Loop and Stat modules instead Shell command with Ansible playbook.  
Whenever I run the playbook with --check, I always get the ‘Pass’ message.

The error was: error while evaluating conditional (audit\_tools.stat.mode != ‘0755’): ‘dict object’ has no attribute ‘stat’\n\n

I need help.

Thanks

---

<div class="post-metadata">

**Author:** ![Roberto\_J\_R\_Paz](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@Roberto\_J\_R\_Paz](https://forum.ansible.com/u/Roberto_J_R_Paz)\
**Post date:** [December 17, 2020, 4:05pm UTC](https://forum.ansible.com/t/need-help-with-loop-and-stat-playbook/34344/2 "2020-12-17T16:05:05Z")

</div>

Maybe some of the files are missing in the target. If that’s the case, there is no “stat” for that file.

Maybe you should add “audit\_tools.stat is defined and audit\_tools.stat.mode != ‘0755’”

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [December 17, 2020, 4:30pm UTC](https://forum.ansible.com/t/need-help-with-loop-and-stat-playbook/34344/3 "2020-12-17T16:30:31Z")

</div>

> Maybe some of the files are missing in the target. If that's the case, there is no "stat" for that file.

That's not true. If a file is missing you have stat.exists = false in the result.

The problem here is that the stat task is called in a loop, while set\_fact is called without a loop.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Thuan1](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@Thuan1](https://forum.ansible.com/u/Thuan1)\
**Post date:** [December 17, 2020, 8:21pm UTC](https://forum.ansible.com/t/need-help-with-loop-and-stat-playbook/34344/4 "2020-12-17T20:21:07Z")

</div>

Hi all,

So I made a slight chance, I added "failed\_when: audit\_tools.stat.mode != ‘0755’’ below ‘register’ module and the error message went away.  
By the way, all files are exist.  
I changed two files chmod to 0640 for testing purpose.  
However, I still get the ‘Passed’ as a result when I ran the --check mode.

---

<div class="post-metadata">

**Author:** ![Thuan1](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@Thuan1](https://forum.ansible.com/u/Thuan1)\
**Post date:** [December 17, 2020, 8:30pm UTC](https://forum.ansible.com/t/need-help-with-loop-and-stat-playbook/34344/5 "2020-12-17T20:30:27Z")

</div>

Another issue, when all the files have proper permissions, then the playbook would give me the result as ‘Failed.’  
This is the opposite of what I want.

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“msg”: “V-219195 FAILED. Audit tools aren’t configured with mode of 0755 or less permissive.”
