Search code examples
ansiblefile-permissionsansible-2.x

Ansible recursively grant read-only access to files


I've a dir /read-only-others-group where users in others group should have read-only access to all files, recursively. I tried with file module:

- name: Ensure /read-only-others-group directory exists and gives read-only access to others group
  file:
    path: /read-only-others-group
    state: directory
    recurse: yes
    owner: someuser
    group: somegroup
    mode: "0754"

This permission doesn't allow users in others group ls or cat a file or cd into the directory or any under it.

It may be solved with shell module like:

find /read-only-others-group -type d -print0 | xargs -0 chmod 755
find /read-only-others-group -type f -print0 | xargs -0 chmod 754

Is there a be a better, idempotent solution?


Solution

  • Q: "Users in other groups should have read-only access"

    A: Use symbolic mode

        mode: "o-w"