# Failed to create temporary directory

**URL:** <https://forum.ansible.com/t/failed-to-create-temporary-directory/35375>\
**Category:** Ansible Project\
**Created:** [June 18, 2021, 7:41pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375 "2021-06-18T19:41:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitesh\_shet](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nitesh\_shet](https://forum.ansible.com/u/nitesh_shet)\
**Post date:** [June 18, 2021, 7:41pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/1 "2021-06-18T19:41:25Z")

</div>

Hi experts,  
I am unable to ping to my remote servers via ansible. Below are how my inventory file is looks like:-

[servers]  
x.y.z

[servers:vars]  
ansible\_user=dummy  
ansible\_ssh\_pass=dummy  
ansible\_python\_interpreter=/usr/bin/python  
ansible\_port=22  
ansible\_become=yes

if i apply ping module using ansible i am getting below error:-

“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 ~/.ansible/tmp`"&& mkdir "`echo ~/.ansible/tmp/ansible-tmp-1624045005.71-29459-71519195524962`" && echo ansible-tmp-1624045005.71-29459-71519195524962="`echo ~/.ansible/tmp/ansible-tmp-1624045005.71-29459-71519195524962`" ), exited with result 1”,  
“unreachable”: true  
}

the method that i followed to overcome this (but not able to):-

1. i had created the .ansible/tmp directory and given 777 permission (not worked)  
2.given 777 permission to default directory of remote(not worked)  
3.changing the remote\_tmp path in ansible.cfg file(not worked)  
4.changing log file path which also has 777 permission in ansible.cfg(not worked)  
5.prmitted root login from sshd

please help me to over come this problem.

my controller node is of centos7 and remote is debian

Thanks,  
Nitesh

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [June 18, 2021, 7:50pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/2 "2021-06-18T19:50:37Z")

</div>

> Hi experts,  
> I am unable to ping to my remote servers via ansible.

Do other ansible commands on the same target machine work okay?

> &nbsp;&nbsp;&nbsp;&nbsp;"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.

What's the definition of your tmp path in ansible.cfg?

> Failed command was: ( umask 77 && mkdir -p \"` echo ~/.ansible/tmp `\"&&  
> mkdir \"` echo ~/.ansible/tmp/ansible-tmp-1624045005.71-29459-71519195524962  
> `\" && echo ansible-tmp-1624045005.71-29459-71519195524962=\"` echo  
> ~/.ansible/tmp/ansible-tmp-1624045005.71-29459-71519195524962 `\" ), exited  
> with result 1",

> the method that i followed to overcome this (but not able to):-  
> 1. i had created the .ansible/tmp directory and given 777 permission (not  
> worked)

> 2.given 777 permission to default directory of remote(not worked)

Which is the "default directory"?

> 3.changing the remote\_tmp path in ansible.cfg file(not worked)

What did you try changing it to?

> 4.changing log file path which also has 777 permission in ansible.cfg(not  
> worked)

I don't believe logging is a problem here.

> 5.prmitted root login from sshd

Which user are you connecting to the remote machine as?

Antony.

---

<div class="post-metadata">

**Author:** ![nitesh\_shet](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nitesh\_shet](https://forum.ansible.com/u/nitesh_shet)\
**Post date:** [June 18, 2021, 8:33pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/3 "2021-06-18T20:33:55Z")

</div>

My remote user has sudo permission and I tried changing remote\_tmp to absolute path in remote host as /home/shared/.ansible/tmp  
Nothing is working, if I do ssh manually to the remote will work.

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [June 18, 2021, 8:38pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/4 "2021-06-18T20:38:42Z")

</div>

Which user do you manually SSH to the remote machine as?

Which user is ansible configured to connect as?

Is "/home/shared" the home directory for either of these users?

What's the definition of your tmp path in ansible.cfg?

Antony.

---

<div class="post-metadata">

**Author:** ![nitesh\_shet](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nitesh\_shet](https://forum.ansible.com/u/nitesh_shet)\
**Post date:** [June 18, 2021, 8:42pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/5 "2021-06-18T20:42:28Z")

</div>

temproot is the user to which I manually did the ssh and /home/shared is also belongs to the temproot user and even in my inventory also I specially mentioned user as temproot.  
~/.ansible/tmp is the path in ansible.cfg

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [June 18, 2021, 8:46pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/6 "2021-06-18T20:46:55Z")

</div>

Please show us a playbook which exhibits this problem (the shortest example  
you can provide which shows it would be good).

Also please copy and paste a short example of a manual SSH session where you  
connect to the remote server as the same user that ansible is using and run  
the same command you have in the playbook.

Antony.

---

<div class="post-metadata">

**Author:** ![nitesh\_shet](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nitesh\_shet](https://forum.ansible.com/u/nitesh_shet)\
**Post date:** [June 18, 2021, 8:53pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/7 "2021-06-18T20:53:26Z")

</div>

[root@in-6centos50-dt ansible]# ssh [temproot@172.16.12.215](mailto:temproot@172.16.12.215) -p 8022  
[temproot@172.16.12.215](mailto:temproot@172.16.12.215)’s password:  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Warning \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
The Linux shell access is restricted to authorized users for business purposes.  
Unauthorized access is a violation of the law.

Infinera  
18-06-2021T21:51

---

<div class="post-metadata">

**Author:** ![nitesh\_shet](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nitesh\_shet](https://forum.ansible.com/u/nitesh_shet)\
**Post date:** [June 18, 2021, 8:54pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/8 "2021-06-18T20:54:15Z")

</div>

ansible all -m ping  
172.16.12.215 | 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 ~/.ansible/tmp`"&& mkdir "`echo ~/.ansible/tmp/ansible-tmp-1624049640.76-30885-21861204789923`" && echo ansible-tmp-1624049640.76-30885-21861204789923="`echo ~/.ansible/tmp/ansible-tmp-1624049640.76-30885-21861204789923`" ), exited with result 1”,  
“unreachable”: true

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [June 18, 2021, 9:00pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/9 "2021-06-18T21:00:25Z")

</div>

'i haven't written any playbook , i am just trying to run "ansible all -m  
ping" from shell.'

Okay.

> [root@in-6centos50-dt ansible]# ssh temproot@172.16.12.215 -p 8022  
> temproot@172.16.12.215's password:

> Below are how my  
> inventory file is looks like:-  
> [servers]  
> x.y.z
> 
> [servers:vars]  
> ansible\_user=dummy  
> ansible\_ssh\_pass=dummy  
> ansible\_python\_interpreter=/usr/bin/python  
> ansible\_port=22  
> ansible\_become=yes

Your manual SSH was to port 8022; your configuration files says port 22.

Your manual SSH was as user temproot, your configuration file says dummy.

Try modifying these things to be consistent and let us know the outcome.

Antony.

---

<div class="post-metadata">

**Author:** ![nitesh\_shet](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nitesh\_shet](https://forum.ansible.com/u/nitesh_shet)\
**Post date:** [June 18, 2021, 9:03pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/10 "2021-06-18T21:03:13Z")

</div>

[servers]  
172.16.12.215

[servers:vars]  
ansible\_user=temproot  
ansible\_ssh\_pass=\*\*\*\*\*\*  
ansible\_python\_interpreter=/usr/bin/python  
ansible\_port=8022

still i am getting the same response.:-

ansible all -m ping  
172.16.12.215 | 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 ~/.ansible/tmp`"&& mkdir "`echo ~/.ansible/tmp/ansible-tmp-1624050122.9-31206-124246621969704`" && echo ansible-tmp-1624050122.9-31206-124246621969704="`echo ~/.ansible/tmp/ansible-tmp-1624050122.9-31206-124246621969704`" ), exited with result 1”,  
“unreachable”: true

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [June 18, 2021, 9:10pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/11 "2021-06-18T21:10:55Z")

</div>

When you run ping in Ansible playbook or ansible they are using the same module. Ansible Ping is not the same as ping. Ansible ping makes an ssh connection to the server.

When ansible runs a module it writes a file to the home directory of the user on the remote machine to get the right permissions. This can be overwritten in Ansible.cfg This error says iT cannot write to /[tmp.it](http://tmp.it) looks like this setting has been over written.

---

<div class="post-metadata">

**Author:** ![nitesh\_shet](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nitesh\_shet](https://forum.ansible.com/u/nitesh_shet)\
**Post date:** [June 18, 2021, 9:15pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/12 "2021-06-18T21:15:53Z")

</div>

But i have given 777 permission to my ~ directory and in ansible.cfg also tried to change the directory path to something else like /home/temproot/.ansible/tmp and /tmp/.ansible/tmp other than already existing one.  
but nothing worked for me. after that i have kept the config file as it is.

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [June 18, 2021, 9:18pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/13 "2021-06-18T21:18:54Z")

</div>

The problem is it is NOT writing to the home directory. It is writing to /tmp directory. Your user has not got rights to the directory. Look for that setting the error message tells you in the ansible.cfg and take it out. Behavior should be the same after that

---

<div class="post-metadata">

**Author:** ![nitesh\_shet](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nitesh\_shet](https://forum.ansible.com/u/nitesh_shet)\
**Post date:** [June 18, 2021, 9:19pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/14 "2021-06-18T21:19:51Z")

</div>

Below is how ansible config file looks like:

# config file for ansible – [https://ansible.com/](https://ansible.com/)

# ===============================================

# nearly all parameters can be overridden in ansible-playbook

# or with command line flags. ansible will read ANSIBLE\_CONFIG,

# ansible.cfg in the current working directory, .ansible.cfg in

# the home directory or /etc/ansible/ansible.cfg, whichever it

# finds first

[defaults]

# some basic default values…

#inventory = /etc/ansible/hosts  
#library = /usr/share/my\_modules/  
#module\_utils = /usr/share/my\_module\_utils/  
#remote\_tmp = ~/.ansible/tmp  
#local\_tmp = ~/.ansible/tmp  
#plugin\_filters\_cfg = /etc/ansible/plugin\_filters.yml  
#forks = 5  
#poll\_interval = 15  
#sudo\_user = root  
#ask\_sudo\_pass = True  
#ask\_pass = True  
#transport = smart  
#remote\_port = 22  
#module\_lang = C  
#module\_set\_locale = False

# plays will gather facts by default, which contain information about

# the remote system.

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [June 18, 2021, 9:22pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/15 "2021-06-18T21:22:52Z")

</div>

Why do you have so much? I just have two or three entries in mine. Role path. and collections path? Are you just copying and pasting? What purpose do yoy need to have so many entries?

---

<div class="post-metadata">

**Author:** ![nitesh\_shet](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nitesh\_shet](https://forum.ansible.com/u/nitesh_shet)\
**Post date:** [June 18, 2021, 9:25pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/16 "2021-06-18T21:25:20Z")

</div>

i just pasted the config file which i got during the ansible installation and made modification on that, can you please specify which entry exactly do i need to change in that config file?

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [June 18, 2021, 9:27pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/17 "2021-06-18T21:27:15Z")

</div>

Don’t. You don’t need to have ansible.cfg to use ansible. Unless there is a setting you need to change. Take it out

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [June 18, 2021, 9:27pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/18 "2021-06-18T21:27:50Z")

</div>

Er, have you uncommented (ie: removed the leading '#') the lines which you  
have altered?

If not, they are still comments, and are ignored.

Antony.

---

<div class="post-metadata">

**Author:** ![nitesh\_shet](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nitesh\_shet](https://forum.ansible.com/u/nitesh_shet)\
**Post date:** [June 18, 2021, 9:31pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/19 "2021-06-18T21:31:52Z")

</div>

i just moved my config file to some unknow directory but after doing that also i am getting the same error :-  
ansible all -m ping  
172.16.12.215 | 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 ~/.ansible/tmp`"&& mkdir "`echo ~/.ansible/tmp/ansible-tmp-1624051861.58-31908-212868002608260`" && echo ansible-tmp-1624051861.58-31908-212868002608260="`echo ~/.ansible/tmp/ansible-tmp-1624051861.58-31908-212868002608260`" ), exited with result 2”,  
“unreachable”: true  
}

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [June 18, 2021, 9:34pm UTC](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375/20 "2021-06-18T21:34:57Z")

</div>

What do the log files such as /var/log/auth.log and /var/log/syslog on the  
Debian machine you are targetting tell you is happening when you run these  
commands on the Centos ansible server?

Antony.

[Next page](https://forum.ansible.com/t/failed-to-create-temporary-directory/35375.md?page=2)
