there. I am new to ansible. I was trying to give some permission to multiple file using ansible. I aleardy tried follwoing code:
- 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
in the above code i want to give permission to tomcat for all .sh file located in tomcat/bin directory.I have already created a tomcat user. When i run this playbook i get this error:
{"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"}
How can i do that?
The file module does not support the use of wildcards in its path
parameter.
You can use a combination of the find and file module as described in a blog post 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 }}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With