7
votes

I am trying to become a user "oracle" in ansible using the following playbook:

- 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

I am receiving an error:

"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"

I have red the article "https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user"

and added the following to /etc/ansible/ansible.cfg without any effect.

allow_world_readable_tmpfiles = True

My Ansible Version:

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]

Question: Is there a way to configure my host to accept ansible's becoming the oracle user?

3

3 Answers

6
votes

To allow becoming non privileged user two things must be set to True in /etc/ansible/ansible.cfg

Important: The given settings must be uncommented at the right locations in ansible.cfg. It is insufficient to append those settings to ansible.cfg.

allow_world_readable_tmpfiles = True
pipelining = True

To uncomment them programmatically do:

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

Here is an example playbook, which shows how to become the user 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
3
votes

As of ansible 2.10, there is more fine-grained control over readability of temporary files (and the use of the global allow_world_readable_tmpfiles variable is deprecated).

E.g. to enable world readability for the shell module you can now set a variable ansible_shell_allow_world_readable_temp: true at the host level (worked for me with ansible 2.10.5).

As of February 2021, documentation still seems to be somewhat lacking; see https://github.com/ansible/ansible/issues/72264

2
votes

If you are on Ubuntu 20.04 or later, you need to install the acl package.

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