Ansible – Mode 755 for directories and 644 for files recursively

Question:

I’d like to allow anyone to list and read all files in my directory tree, but I don’t want to make the files executable :

The following task makes my directories and files readable, but it makes all the files executable as well:

On the other hand, if I choose mode 0644, then all my files are not executable, but I’m not able to list my directories.

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

Answer:

Since version 1.8, Ansible supports symbolic modes. Thus, the following would perform the task you want:

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

Leave a Reply