Ansible:更改.yml文件中目录内文件的权限

时间:2016-08-03 19:01:58

标签: ansible

假设有一个目录/ dir / tools。 工具包含一堆脚本,比如a.sh,b.sh,c.sh。

我需要将a.sh,b.sh和c.sh的权限设置为0775。

我目前以下列方式完成:

ordered_info = [(i,my_dic[i]) for i in my_criteria]

顺便说一下,'file:path = / dir / tools owner = abc group = abc mode = 0775'设置工具目录的权限,但不设置其中文件的权限。

有没有更好的方法来实现这一目标?

4 个答案:

答案 0 :(得分:7)

尝试:

- name: Fix 'support_tools' permissions
  file: path=/dir/tools owner=abc group=abc mode=0775 state=directory recurse=yes

答案 1 :(得分:0)

您也可以跳过指定组。然后通过使用--check参数运行它来检查你的yml文件。

答案 2 :(得分:0)

尝试:

- name: Fix 'support_tools' permissions
   shell: 'chmod a+x /dir/tools/*'

答案 3 :(得分:0)

这是使用不带“ shell”或“ command”的ansible模块的另一种方法。

- name: lookup files with a certain pattern
  find:
    paths: /dir/tools/
    file_type: file
    patterns: "*.sh"
  register: filelist

- name: change permissions
  file:
    path: "{{ item.path }}"
    state: file
    owner: abc
    group: abc
    mode: "0775"
  with_items: "{{ filelist.files }}"
相关问题