Ansible - find and set permissions, including sticky bit
Goal: set the permission to 775 and g+s in one task.
- name: Set permissions for found directories
file:
path: "{{ item }}"
owner: root
group: vagrant
mode: 02775
state: directory
recurse: no #cause it already found recurse
with_items: ____
But I don't understand why you were checking for SUID (-perm /1000
) and setting SGID (g+s
) in the code. Neither I know what is the value of find
, because you registered find1
and find2
, but not find
.
I also don't see a need to specify conditions for find, because Ansible module is idempotent/declarative and you want all directories to have the same permissions, so you can rely on Ansible.
Found it, one can use the official file module.
- name: Set sticky bit + 775 for directory
file:
path: /tmp/test
owner: root
group: vagrant
mode: u=rwx,g=rwx,o=rx,g+s
# mode: '02775' # also works
# mode: ug=rwx,o=rx,g+s # also works
state: directory