Ansible-递归的目录模式755和文件的644 [英] Ansible - Mode 755 for directories and 644 for files recursively

查看:184
本文介绍了Ansible-递归的目录模式755和文件的644的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许任何人列出并读取目录树中的所有文件,但我不想使这些文件可执行:

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 :

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

以下任务使我的目录和文件可读,但使所有文件也可执行:

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

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

另一方面,如果我选择模式0644,则我的所有文件都不可执行,但是我无法列出目录.

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.

是否可以为目录树中的所有目录设置模式755,为所有文件设置模式644?

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

谢谢.

推荐答案

从1.8版开始,Ansible支持符号模式.因此,以下将执行您想要的任务:

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

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

因为X(而不是x)仅适用于设置了至少一个x位的目录或文件.

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

这篇关于Ansible-递归的目录模式755和文件的644的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆