Ansible - mode 755 for directories and 644 for files recursively

I would like to allow all users to list and read all files in my directory tree, but I do not want the files to be executed:

dir \subdir1 file1 \subdir2 file2 ... \subdirX fileX 

The following task makes my directories and files readable, but also makes all files executable:

 - name: Make my directory tree readable file: path: dir mode: 0755 recurse: yes 

On the other hand, if I select 0644 mode, then all my files are not executed, but I cannot list my directories.

Is it possible to set the mode to 755 for all directories and 644 for all files in the directory tree?

Thank.

+53
file-permissions ansible
Feb 28 '15 at 6:05
source share
2 answers

Starting with version 1.8, Ansible supports symbolic modes. Thus, the following task will fulfill the required task:

 - name: Make my directory tree readable file: path: dir mode: u=rwX,g=rX,o=rX recurse: yes 

Since X (instead of x) applies only to directories or files with at least one set of bits.

+79
Apr 22 '15 at 9:52
source share

Ansible file / copy modules do not give you granularity of permission jobs based on file type, so you will most likely need to do this manually by doing something in this direction:

 - name: Ensure directories are 0755 command: find {{ path }} -type d -exec chmod -c 0755 {} \; register: chmod_result changed_when: "chmod_result.stdout != \"\"" - name: Ensure files are 0644 command: find {{ path }} -type f -exec chmod -c 0644 {} \; register: chmod_result changed_when: "chmod_result.stdout != \"\"" 

This will cause recursion through {{ path }} and change the permissions of each file or directory to the specified permissions.

+20
Feb 28 '15 at 14:26
source share



All Articles