我正在尝试使用ansible更新远程服务器上特定目录中所有shell脚本的权限,但它给了我错误:
- name: update permissions
file: dest=/home/goldy/scripts/*.sh mode=a+x
这是我得到的错误:
fatal: [machineA]: FAILED! => {"changed": false, "msg": "file (/home/goldy/scripts/*.sh) is absent, cannot continue", "path": "/home/goldy/scripts/*.sh", "state": "absent"}
to retry, use: --limit @/var/lib/jenkins/workspace/copy/copy.retry
我在这里做错了什么?
答案 0 :(得分:0)
您应该使用find模块运行任务以收集该目录上的所有.sh文件,并将结果注册到变量中。 然后使用文件模块运行第二个任务,该文件模块将在文件的扩展名以.sh结尾时更新权限。
检查样本剧本:
- hosts: localhost
gather_facts: false
vars:
tasks:
- name: parse /tmp directory
find:
paths: /tmp
patterns: '*.sh'
register: list_of_files
- debug:
var: item.path
with_items: "{{ list_of_files.files }}"
- name: change permissions
file:
path: "{{ item.path }}"
mode: a+x
with_items: "{{ list_of_files.files }}"