Failed to create temporary directory

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

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

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

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

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.

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.

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

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.

[root@in-6centos50-dt ansible]# ssh temproot@172.16.12.215 -p 8022
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

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

'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.

[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

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 looks like this setting has been over written.

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.

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

Below is how ansible config file looks like:

config file for ansible – 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.

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?

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?

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

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

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

Antony.

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
}

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.