UNREACHABLE! => {"changed": false, "msg": "Failed to create temporary directory.

Hi all,

i’ve been having this Problem since a few weeks already and could not seem to find the cause to the problem.

Setup:
OS: NAME=“Red Hat Enterprise Linux Server” ; VERSION=“7.9 (Maipo)”
Ansible Version: ansible 2.9.15

Problem:

fatal: [my_server]: UNREACHABLE! => {“changed”: false, “msg”: “Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in "/tmp", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p "echo /var/tmp"&& mkdir "echo /var/tmp/ansible-tmp-1649263609.0-35845-182209786710290" && echo ansible-tmp-1649263609.0-35845-182209786710290="echo /var/tmp/ansible-tmp-1649263609.0-35845-182209786710290" ), exited with result 1”, “unreachable”: true}

  • Jobs are executed from a scheduling System which access the ansible server to execute the playbook from there.
  • The Job does ends successfully, but also sometimes with the above fatal message.
  • A “rerun” of the failed job will not produce the same error.
  • This Error is not limited to the ansible module and is quite difficult to reproduce. It occurs randomly on any server using any ansible module.

I’ve already tried these ansible.cfg settings. Unfortunately, it did not help.

remote_tmp = /tmp/.ansible-${USER}/tmp
system_tmpdirs = /tmp
pipelining = True

[ssh_connection]
retries=10

Has anyone encounter similar problem such as this or an idea how to resolve this?

Best Regards,
JB

additionaly, i ran the playbook with the option -vvv. Ansible seem to have created the directory, however returned a 255 which triggered an ssh-retry. The ssh-retry returned with an exit 1 since the directory already exists.

<my_server> ESTABLISH SSH CONNECTION FOR USER: None
<my_server> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=360 -o ControlPath=/home/ansible/.ansible/cp/f52420a193 my_server ‘/bin/sh -c ‘"’“‘rm -f -r /tmp/ansible-tmp-1651552384.85-38092-103098107436542/ > /dev/null 2>&1 && sleep 0’”’“‘’
<my_server> (0, ‘’, ‘’)
<my_server> ESTABLISH SSH CONNECTION FOR USER: None
<my_server> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=360 -o ControlPath=/home/ansible/.ansible/cp/f52420a193 my_server '/bin/sh -c '”‘"’( umask 77 && mkdir -p “echo /tmp”&& mkdir “echo /tmp/ansible-tmp-1651552386.34-38125-21691224005877” && echo ansible-tmp-1651552386.34-38125-21691224005877=“echo /tmp/ansible-tmp-1651552386.34-38125-21691224005877” ) && sleep 0’“'”‘’
<my_server> (255, ‘’, ‘’)
<my_server> ssh_retry: attempt: 1, ssh return code is 255. cmd ([‘ssh’, ‘-C’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘ConnectTimeout=360’, ‘-o’, ‘ControlPath=/home/ansible/.ansible/cp/f52420a193’, ‘my_server’, ‘/bin/sh -c '( umask 77 && mkdir -p “echo /tmp”&& mkdir “echo /tmp/ansible-tmp-1651552386.34-38125-21691224005877” && echo ansible-tmp-1651552386.34-38125-21691224005877=“echo /tmp/ansible-tmp-1651552386.34-38125-21691224005877” ) && sleep 0'’]…), pausing for 0 seconds
<my_server> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=360 -o ControlPath=/home/ansible/.ansible/cp/f52420a193 my_server ‘/bin/sh -c ‘"’"’( umask 77 && mkdir -p “echo /tmp”&& mkdir “echo /tmp/ansible-tmp-1651552386.34-38125-21691224005877” && echo ansible-tmp-1651552386.34-38125-21691224005877=“echo /tmp/ansible-tmp-1651552386.34-38125-21691224005877” ) && sleep 0’“'”‘’
<my_server> (1, ‘’, ‘mkdir: das Verzeichnis \xbb/tmp/ansible-tmp-1651552386.34-38125-21691224005877\xab kann nicht angelegt werden: Die Datei existiert bereits\n’)
<my_server> Failed to connect to the host via ssh: mkdir: das Verzeichnis ?/tmp/ansible-tmp-1651552386.34-38125-21691224005877? kann nicht angelegt werden: Die Datei existiert bereits

TASK [stat] ********************************************************************

task path: /home/ansible/inventory/playbooks/1_deployments/wildfly_debug.yml:24

fatal: [ my_server ]: UNREACHABLE! => {

“changed”: false,

“msg”: “Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in "/tmp", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p "echo /tmp"&& mkdir "echo /tmp/ansible-tmp-1651552386.34-38125-21691224005877" && echo ansible-tmp-1651552386.34-38125-21691224005877="echo /tmp/ansible-tmp-1651552386.34-38125-21691224005877" ), exited with result 1”,

“unreachable”: true

}