无法为 Ansible 任务设置 umask

Alj*_*aus 6 linux umask ansible

我正在尝试使用特定的(0002)运行任意 Ansible 模块umask

一些 Ansible 模块(例如git)支持umask参数(或mode直接设置权限的参数),但许多模块不支持。
据我所知,Ansible 不会调用 shell(除非您使用该shell模块),因此更改 shell 配置文件中的 umask 是没有用的。
我的方法是更改UMASK​​ 中的行/etc/login.defs,但这对 Ansible 没有影响。仍为umask0022。PAM
似乎配置为包括pam_umask.so.

我知道我可以使用该shell模块作为解决方法(shell: umask 0002; some_command),但这似乎是一个丑陋的黑客。

我如何让 Ansible 尊重我的umask

这是针对 CentOS 8 系统的 Ansible 2.9.9。

bba*_*iee 1

可以更改远程主机的 umask,最简单的方法是~/.bash_profile编辑remote_user

umask 0002
Run Code Online (Sandbox Code Playgroud)

要使用该设置,您需要更改ansible,cfg中的可执行文件,或在清单中使用ansible_shell_executable中使用:

[demo]
example.com ansible_shell_executable='/bin/bash -l'
Run Code Online (Sandbox Code Playgroud)

为什么这有效?-l参数强制 bash 充当登录 shell,获取配置文件。

验证在运行 ansible 或 ansible-playbook 时使用详细信息,您将看到任何 Ansible 模块都从with 参数-vvv运行(并添加),您将看到类似以下内容的内容:executable-l-c

EXEC /bin/bash -l -c '/usr/libexec/platform-python /home/demo/.ansible/tmp/ansible-tmp-1706875415.3499873-5842-271431387344170/AnsiballZ_command.py && sleep 0'
Run Code Online (Sandbox Code Playgroud)