假设有一个目录/ dir/tools.工具包含一堆脚本,比如a.sh,b.sh,c.sh.
我需要将a.sh,b.sh和c.sh的权限设置为0775.
我目前以下列方式完成:
- name: Fix 'support_tools' permissions
file: path={{ item }} owner=abc group=abc mode=0775
with_items:
- /dir/tools/a.sh
- /dir/tools/b.sh
- /dir/tools/c.sh
Run Code Online (Sandbox Code Playgroud)
顺便说一下,'file:path =/dir/tools owner = abc group = abc mode = 0775'设置工具目录的权限,但不设置其中的文件.
有没有更好的方法来实现这一目标?
尝试:
- name: Fix 'support_tools' permissions
file: path=/dir/tools owner=abc group=abc mode=0775 state=directory recurse=yes
Run Code Online (Sandbox Code Playgroud)
这是另一种方法,使用没有“shell”或“命令”的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 }}"
Run Code Online (Sandbox Code Playgroud)
尝试使用下面的“with_items”行和 -maxdepth 5
vars:
your_path: "/home/username/support_tools"
tasks:
- name: Fix 'support_tools' permissions
command: "{{ item }}"
with_items:
- find {{ your_path }} -maxdepth 5 -type d ! -perm 0755 -exec chmod 0755 {} \;
- find {{ your_path }} -maxdepth 5 -type f ! -perm 0644 -exec chmod 0644 {} \;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17792 次 |
| 最近记录: |