在 ansible 中成为非 root 用户失败

Ski*_*kip 6 ansible

我正在尝试使用以下剧本在 ansible 中成为用户“oracle”:

- hosts: "myhost"
  tasks:         
        - name: install oracle client
          become: yes
          become_user: oracle
          become_method: su
          shell: |
                whoami
          args:
            chdir: /tmp/client
          environment:
            DISTRIB: /tmp/client
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

"msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chown: changing ownership of `/tmp/ansible-tmp-1513617986.78-246171259298529/': Operation not permitted\nchown: changing ownership of `/tmp/ansible-tmp-1513617986.78-246171259298529/command.py': Operation not permitted\n}). For information on working around this, see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user"
Run Code Online (Sandbox Code Playgroud)

我有红色文章“ https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user

并将以下内容添加到/etc/ansible/ansible.cfg没有任何影响。

allow_world_readable_tmpfiles = True
Run Code Online (Sandbox Code Playgroud)

我的 Ansible 版本:

ansible 2.4.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
Run Code Online (Sandbox Code Playgroud)

问题: 有没有办法配置我的主机以接受 ansible 成为 oracle 用户?

And*_*art 8

如果您使用的是 Ubuntu 20.04 或更高版本,则需要安装该acl软件包。

来源:https ://github.com/georchestra/ansible/issues/55#issuecomment-651043423


Ski*_*kip 5

要允许变得不特权用户两件事情必须设置为True/etc/ansible/ansible.cfg

重要提示: 必须在ansible.cfg. 将这些设置附加到ansible.cfg.

allow_world_readable_tmpfiles = True
pipelining = True
Run Code Online (Sandbox Code Playgroud)

要以编程方式取消注释它们,请执行以下操作:

sed -i 's/.*pipelining.*/pipelining = True/' /etc/ansible/ansible.cfg
sed -i 's/.*allow_world_readable_tmpfiles.*/allow_world_readable_tmpfiles = True/' /etc/ansible/ansible.cfg
Run Code Online (Sandbox Code Playgroud)

这是一个示例剧本,展示了如何成为用户oracle

# Setup the infrastructure for Faktura
- hosts: "myhost"
  become: yes
  become_method: sudo
  become_user: oracle
  vars:
    allow_world_readable_tmpfiles: true
  tasks:         


        # an error is thorwn when becoming unpriviledged user. Hence use sudo
        - name: install oracle client
          shell: |
                whoami
          args:
            chdir: /tmp/client
          environment:
            DISTRIB: /tmp/client
Run Code Online (Sandbox Code Playgroud)


leo*_*irz 5

从 ansible 2.10 开始,对临时文件的可读性有了更细粒度的控制(并且allow_world_readable_tmpfiles不推荐使用全局变量)。

例如,为了使shell模块具有世界可读性,您现在可以在主机级别设置一个变量ansible_shell_allow_world_readable_temp: true(适用于我的 ansible 2.10.5)。

截至 2021 年 2 月,文档似乎仍然有些缺乏;请参阅https://github.com/ansible/ansible/issues/72264