ansible - 在 ansible 中成为非 root 用户失败

标签 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

我收到一个错误:
"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"

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

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

我的 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]

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

最佳答案

要允许成为非特权用户,必须将两件事设置为 True/etc/ansible/ansible.cfg
重要提示:
必须在 ansible.cfg 中的正确位置取消对给定设置的注释。 .
将这些设置附加到 ansible.cfg 是不够的.

allow_world_readable_tmpfiles = True
pipelining = True

要以编程方式取消注释它们,请执行以下操作:
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

这是一个示例剧本,展示了如何成为用户 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

关于ansible - 在 ansible 中成为非 root 用户失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47873671/

相关文章:

python - Ansible 在远程服务器上找不到自定义 python 模块

ansible - 在哪里可以获得 Ansible 预定义变量的列表?

ansible - 在 ansible playbook 中 Ping 主机

reactjs - 如何使用Ansible访问React中的环境变量

Ansible:在容器创建期间获取 docker 容器输出

ansible - ansible 中的换行符 - var 提示符

ssh - 主机 user@ip_address 的 Ansible "Could not resolve hostname"错误

ssh - Ansible:如何让 Paramiko 使用 ~/.ssh/config?

如果任务失败,Ansible Vault 密码会显示在日志中

cron - 为什么我的 Ansible 的 cronjob 设置没有运行?