Ansible:更改文件的权限而不是目录的权限
Ansible: Changing permissions of files but not of directory
我需要设置目录下文件的权限,但我不想更改目录的权限。
我试过这个:
- name: chmod 444
file: /dir recurse=yes state=directory owner=abc group=abc mode=0444
但它也会修改目录权限。可能吗?
不在一项任务中。
您需要先找到文件,然后根据列表使用适当的设置执行 file
模块。
- find:
path: /dir
file_type: file
recurse: yes
register: find_result
- file:
path: "{{ item.path }}"
owner: abc
group: abc
mode: 0444
with_items: "{{ find_result.files }}"
在一项任务中使用 shell:
- shell: "find . -type f -exec chmod 0444 {} \;"
args:
chdir: /dir
我需要设置目录下文件的权限,但我不想更改目录的权限。
我试过这个:
- name: chmod 444
file: /dir recurse=yes state=directory owner=abc group=abc mode=0444
但它也会修改目录权限。可能吗?
不在一项任务中。
您需要先找到文件,然后根据列表使用适当的设置执行 file
模块。
- find:
path: /dir
file_type: file
recurse: yes
register: find_result
- file:
path: "{{ item.path }}"
owner: abc
group: abc
mode: 0444
with_items: "{{ find_result.files }}"
在一项任务中使用 shell:
- shell: "find . -type f -exec chmod 0444 {} \;"
args:
chdir: /dir