Need help with Loop and Stat playbook

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

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’”

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
       Racke

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.

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.”