gpt4 book ai didi

ansible - 如何在使用 Ansible 授予文件权限的同时使用通配符?

转载 作者:行者123 更新时间:2023-12-04 13:03:00 24 4
gpt4 key购买 nike

那里。我是 ansible 的新手。我试图使用 ansible 为多个文件授予一些权限。我已经尝试过以下代码:

- hosts: all
tasks:
- name: Giving file permission to tomcat/bin sh file
file: path=/tomcat/apache-tomcat-8.5.23/bin/*.sh owner=tomcat group=tomcat mode=755

在上面的代码中,我想为位于 tomcat/bin 目录中的所有 .sh 文件授予 tomcat 权限。我已经创建了一个 tomcat 用户。当我运行此剧本时,出现此错误:
 {"changed": false, "msg": "file (/tomcat/apache-tomcat-8.5.23/bin/*.sh) is absent, cannot continue", "path": "tomcat/apache-tomcat-8.5.23/bin/*.sh", "state": "absent"}

我怎样才能做到这一点?

最佳答案

文件 模块不支持在其 path 中使用通配符范围。
您可以使用 的组合查找 文件 博客文章中描述的模块 here :

- hosts: all
tasks:
- name: Find files
find:
paths: /tomcat/apache-tomcat-8.5.23/bin
patterns: "*.sh"
register: files_to_change

- name: Modify the file permissions
file:
path: "{{ item.path }}"
owner: tomcat
group: tomcat
mode: 755
with_items: "{{ files_to_change.files }}"

关于ansible - 如何在使用 Ansible 授予文件权限的同时使用通配符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50288543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com