Change files permissions with loop

Hi all,

My playbook is working for single files but not for directories.
It doesn’t check the folders permissions recursively.

Hi Thuan,

I’m not sure why you are just trying to assert the permissions rather than enforce them, but why not enforce them with something like:

  • name: Change permissions recursively
    hosts: all
    gather_facts: False
    ignore_errors: True

vars:
path:
modes:
d: ‘2755’
f: ‘0640’

tasks:

  • name: Change permissions
    command: find “{{ path }}” -type “{{ item.key }}” ! -perm “{{ item.value }}” -exec chmod -f “{{ item.value }}” {} ;
    with_dict: “{{ modes }}”
    register: result
    changed_when: result.stdout != “”

Hi,

I want to use the block and rescue format.
I want to check the file permissions before change it.

Hi all,

My playbook is working for single files but not for directories.
It doesn't check the folders permissions recursively.

I would use the find module, which works recursively and provides similar information
as the stat module. You also get a single list as you don't need a loop.

Regards
         Racke

I know I can use the shell command with find to get the result.
But it doesn’t seem nice as the loop module.

Thanks

Hello,

Can somebody give me some examples of find module for this case ?

Nvm, I found an alternative solution.
Using find module and loop for this purpose.