Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ansible:更改文件的权限,但不更改目录的权限_Ansible_Ansible 2.x - Fatal编程技术网

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

Ansible:更改文件的权限,但不更改目录的权限,ansible,ansible-2.x,Ansible,Ansible 2.x,我需要设置目录下文件的权限,但我不想更改目录的权限 我试过这个: - name: chmod 444 file: /dir recurse=yes state=directory owner=abc group=abc mode=0444 但它也会修改目录权限。可能吗?不是一项任务 您需要首先查找文件,然后根据列表执行带有适当设置的文件模块 - find: path: /dir file_type: file recurse: yes register: fin

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

我试过这个:

- name: chmod 444
  file: /dir recurse=yes state=directory owner=abc group=abc mode=0444
但它也会修改目录权限。可能吗?

不是一项任务

您需要首先查找文件,然后根据列表执行带有适当设置的
文件
模块

- 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

请查看帮助中心:。