What is the best way to chmod + x a file with ansible.
Converting the following script to ansible format.
mv /tmp/metadata.sh /usr/local/bin/meta.sh chmod +x /usr/local/bin/meta.sh
This is what I have so far..
- name: move /tmp/metadata.sh to /usr/local/bin/metadata.sh command: mv /tmp/metadata.sh /usr/local/bin/metadata.sh
The parameter “mode” sets the permissions in the UNIX way of the file/directory. The state defines the type of object we are modifying, the default is “file” but we could handle also directories, hardlink, symlink, or only update the access time with the “touch” option.
recurse. boolean. added in 1.1 of ansible.builtin. Recursively set the specified file attributes on directory contents. This applies only when state is set to directory .
The lineinfile - module is the best option, if you just want to add, replace or remove one line. The replace - module is best, if you want to add, replace or delete several lines.
ansible
has mode
parameter in file
module exactly for this purpose.
To add execute permission for everyone (i.e. chmod a+x
on command line):
- name: Changing perm of "/foo/bar.sh", adding "+x" file: dest=/foo/bar.sh mode=a+x
Symbolic modes are supported since version 1.8, on a prior version you need to use the octal bits.
The mode
parameter should be specified when using the copy module.
Example:
- name: copy file and set permissions copy: src: script.sh dest: /directory/script.sh mode: a+x
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