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

查看:28
本文介绍了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天全站免登陆