Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: Changing permissions of files inside a directory in .yml file

Tags:

ansible

Suppose there's a directory /dir/tools. tools contains a bunch of scripts, say, a.sh, b.sh, c.sh.

I need to set the permissions of a.sh, b.sh, and c.sh to 0775.

I've currently done it in the following manner:

- 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

Btw, 'file: path=/dir/tools owner=abc group=abc mode=0775' sets the permission of tools directory but not of the files inside it.

Is there a better way of achieving this?

like image 864
gvij Avatar asked Aug 03 '16 19:08

gvij


People also ask

How do you change the permission of all the files in a directory?

To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or “a” (for all). chmod ugo+rwx foldername to give read, write, and execute to everyone. chmod a=r foldername to give only read permission for everyone.

Which parameter is used to change the permission of a file in ansible?

Btw, 'file: path=/dir/tools owner=abc group=abc mode=0775' sets the permission of tools directory but not of the files inside it.

What is the command to change permissions on a directory?

We can change the permissions of files and directories using the chmod command. There are two ways to change permission: Using short/soft/symbolic codes. Using octal codes.


1 Answers

Try:

- name: Fix 'support_tools' permissions
  file: path=/dir/tools owner=abc group=abc mode=0775 state=directory recurse=yes
like image 178
Konstantin Suvorov Avatar answered Oct 06 '22 09:10

Konstantin Suvorov