bartek lab
bartek lab

Reputation: 51

Ansible Failed to set permissions on the temporary files

I'd like to make a playbook that shows me the user currently in use.

this is my ansible cfg:

[defaults]
inventory=inventory
remote_user=adminek

[privilege_escalation]
become=true

[ssh_connection]
allow_world_readable_tmpfiles = True
ssh_args = -o ControlMaster=no -o ControlPath=none -o ControlPersist=no
pipelining = false

and this is my playbook

---
- name: show currenty users 
  hosts: server_a
  
  tasks:
    - name: test user - root
      shell: "whoami"
      register: myvar_root

    - name: test user - user2
      become: true
      become_user: user2    
      shell: "whoami"
      register: myvar_user2


    - name: print myvar root
      debug:
        var: myvar_root.stdout_lines

    - name: print myvar user2
      debug:
        var: myvar_user2.stdout

taks "test user - root" work fine and give me output

ok: [172.22.0.134] => {
    "myvar_root.stdout_lines": [
        "root"
    ]
}

taks "test user - user2" give me output

fatal: [172.22.0.134]: FAILED! => {"msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chown: changing ownership `/var/tmp/ansible-tmp-1621340458.2-11599-141854654478770/': Operation permited\nchown: changing ownership `/var/tmp/ansible-tmp-1621340458.2-11599-141854654478770/AnsiballZ_command.py': Operation permited\n}). For information on working around this, see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user"}

Explanation: adminek- sudoer user User2 - non sudoers users

OS - Scientific Linux release 6.9

Additionaly I hgad similar problem on ubuntu 18.04 but when i installed acl begun works

Someone know what is wrong? Thanks for help!

Upvotes: 4

Views: 4926

Answers (3)

Marcos Vile
Marcos Vile

Reputation: 65

for me it worked installing the acl package in host

- name: Install required packaged
      yum:
        name: "{{ item }}"
        state: present
      with_items:
        - acl
        - python3-pip

in my case I used centos/07, if you use ubuntu, change yum to apt.

Upvotes: -2

bartek lab
bartek lab

Reputation: 51

@F1ko thanks for reply.

I did what you wont and I installed acl on my host, but steal was wrong. I added to visudo.

Defaults:user2 !requiretty
Defaults:adminek !requiretty

I dont know it's ok and secure but work.

Upvotes: 1

F1ko
F1ko

Reputation: 4224

One of the following options should fix your issue:

  • Ensure sudo is installed on the remote host
  • Ensure acl is installed on the remote host
  • Uncomment the following lines in /etc/ansible/ansible.cfg:
allow_world_readable_tmpfiles = True
pipelining = True

Upvotes: 4

Related Questions