Ansible playbook - setup.py - permission denied

I am trying to run a playbook from Ansible 2.3.1.0.

My remote machine is a RHEL7 with Python installed to /usr/bin/python.

My playbook looks like this:

---
- hosts: my-test
  remote_user: myuser
  become: true
  become_method: sudo

  tasks:
#Extend /opt to 1GB
  - name: Extend /opt 2048m.
    lvol:
      vg: rootvg
      lv: rootvg-opt
      size: 1024m

The error I receive:

fatal: [my-test.host.nu]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to my-test.host.nu closed.\r\n", "module_stdout": "/usr/bin/python: can't open file '/home/myuser/.ansible/tmp/ansible-tmp-1523204435.39-113929450187838/setup.py': [Errno 13] Permission denied\r\n", "msg": "MODULE FAILURE", "rc": 1}

The file “setup.py”, created by Ansible , has permissions “-rwx — --- myuser myuser”. 

What am I doing wrong?

I managed to pinpoint the problem. The setup.py file should never have been created in the home folder “/home/myuser” where root has no access.

I tried setting the environment variable TMPDIR and the variable “remote_tmp” in ansible.cfg as below.

ansible.cfg :

remote_tmp = /tmp/ansible-$USER

The problem was, I had missed to include the “[defaults]” “section header” before specifying the “remote_tmp” parameter. The below ansible.cfg file worked as expected.

ansible.cfg :

[defaults]
remote_tmp = /tmp/ansible-$USER
6 Likes

Thanks for coming in 

1 Like

Done the changes in the ansible.cfg file but having same error.

[defaults]

remote_tmp = /tmp/ansible-$USER

some basic default values…

hostfile = inventory

fatal: [vxpim]: FAILED! => {
“changed”: false,
“module_stderr”: “OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: /etc/ssh/ssh_config line 72: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 4 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 18138\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to vxpim closed.\r\n”,
“module_stdout”: " File “/tmp/ansible-vikjain/ansible-tmp-1552938297.39-143951237435117/AnsiballZ_setup.py”, line 39\r\n with open(module, ‘wb’) as f:\r\n ^\r\nSyntaxError: invalid syntax\r\n",
“msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”,
“rc”: 1
}

Hi,

Did you manage to find the solution? havin the same issue…

1 Like

This fixed it for me, thanks!

How was this fixed ?