Warm tip: This article is reproduced from serverfault.com, please click

Ansible recursively grant read-only access to files

发布于 2020-12-04 10:17:02

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?

Questioner
moazzem
Viewed
11
Vladimir Botka 2020-12-04 18:49:40

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

A: Use symbolic mode

    mode: "o-w"