Ansible:更改文件的权限,但不更改目录的权限

时间:2017-06-07 12:34:09

标签: ansible ansible-2.x

我需要在目录下设置文件的权限,但我不想更改目录的权限。

我试过了:

- name: chmod 444
  file: /dir recurse=yes state=directory owner=abc group=abc mode=0444

但它也会修改目录权限。有可能吗?

2 个答案:

答案 0 :(得分:2)

不在一项任务中。

首先需要查找文件,然后使用相应的设置执行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 }}"

答案 1 :(得分:0)

在使用 shell 的一项任务中:

- shell: "find . -type f -exec chmod 0444 {} \\;"
  args:
    chdir: /dir
相关问题