20

I am using ansijet to automate the ansible playbook to be run on a button click. The playbook is to stop the running instances on AWS. If run, manually from command-line, the playbook runs well and do the tasks. But when run through the web interface of ansijet, following error is encountered

Authentication or permission failure.  In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in "/tmp". Failed command was: mkdir -p $HOME/.ansible/tmp/ansible-tmp-1390414200.76-192986604554742 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1390414200.76-192986604554742 && echo $HOME/.ansible/tmp/ansible-tmp-1390414200.76-192986604554742, exited with result 1:

Following is the ansible.cfg configuration.

# some basic default values...

inventory      = /etc/ansible/hosts
#library        = /usr/share/my_modules/
remote_tmp     = $HOME/.ansible/tmp/
pattern        = *
forks          = 5
poll_interval  = 15
sudo_user      = root
#ask_sudo_pass = True
#ask_pass      = True
transport      = smart
#remote_port    = 22
module_lang    = C

I try to change the remote_tmp path to /home/ubuntu/.ansible/tmp But still getting the same error.

Ajeet Khan
  • 8,582
  • 8
  • 42
  • 65

5 Answers5

19

By default, the user Ansible connects to remote servers as will be the same name as the user ansible runs as. In the case of Ansijet, it will try to connect to remote servers with whatever user started Ansijet's node.js process. You can override this by specifying the remote_user in a playbook or globally in the ansible.cfg file.

Ansible will try to create the temp directory if it doesn't already exist, but will be unable to if that user does not have a home directory or if their home directory permissions do not allow them write access.

I actually changed the temp directory in my ansible.cfg file to point to a location in /tmp which works around these sorts of issues.

remote_tmp = /tmp/.ansible-${USER}/tmp

Dave Snigier
  • 2,574
  • 3
  • 21
  • 29
  • ansijet is running as ubuntu user. I changed `remote_user` and `remote_tmp` path as per you said. But still facing the same error. – Ajeet Khan Feb 03 '16 at 15:36
  • Is it the same exact error or did the message change after editing the ansible.cfg remote_tmp config? – Dave Snigier Feb 03 '16 at 15:55
  • There were two playbook, one is to start the instance other is to stop it. Now after changing as per your suggestion, the playbook to start the instances is running well, but getting the same error in the playbook to stop the instance. – Ajeet Khan Feb 03 '16 at 17:31
  • Look at the options that are different between the playbooks. Strip things down to their bare minimum and start adding back roles and options until things break. – Dave Snigier Feb 04 '16 at 13:23
  • 1
    how to give remote temp path for windows 10?? – Malinda Peiris Dec 12 '19 at 05:20
  • I added the `remote_tmp` variable but Im facing the same error with different remote folder ahah :/ someone have fixed it ? – Carlos Andres Jul 09 '20 at 05:26
  • For me it was using an user other than mine in the remote to, so I just added this in my local machine, `/etc/ansible/ansible.cfg` file and was done with it: `[defaults] remote_tmp = .ansible/tmp` The error was, `...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 /home/ubuntu/.ansible/tmp `\"&& mkdir` – Jose Quijada Oct 21 '21 at 23:56
  • This link suggests that `/etc/ansible/ansible.cfg` is one place to override default configs, https://docs.ansible.com/ansible/latest/installation_guide/intro_configuration.html#getting-the-latest-configuration – Jose Quijada Oct 22 '21 at 00:02
1

I faced the same problem a while ago and solved like this . The possible case is that either the remote server's /tmp directory did not have enough permission to write . Run the ls -ld /tmp command to make sure its output looks something like this drwxrwxrwt 7 root root 20480 Feb 4 14:18 /tmp I have root user as super user and /tmp has 1777 permission .

Also for me simply - remote_tmp = /tmp worked well.

Another check would be to make sure $HOME is present from the shell which you are trying to run . Ansible runs commands via /bin/sh shell and not /bin/bash.Make sure that $HOME is present in sh shell .

Ankit Kulkarni
  • 1,245
  • 3
  • 14
  • 23
  • 1
    /tmp has special permissions on linux systems (sticky bit), it is not simply 777 which could be a security vulnerability to certain applications that use /tmp. Using /tmp on its own breaks if any other user ever runs playbooks against these machines (they'll get a permissions error) – Dave Snigier Feb 04 '16 at 13:26
  • Yeah you are right . Sticky bit should be set on `/tmp` . Its set on mine too so the permissions should be 1777 and not 0777. Corrected in above answer. Thanks for pointing it out – Ankit Kulkarni Feb 05 '16 at 06:19
  • Never ran playbook with two users simultaneously . But yeah it could be a possible case and might break if two different users use it at the same time . – Ankit Kulkarni Feb 05 '16 at 06:29
0

In my case I needed to login to the server for the first time and change the default password.

Angus
  • 96
  • 7
0

Check the ansible user on the remote / client machine as this error occurs when the ansible user password expires on the remote / client machine.

==========
'WARNING: Your password has expired.\nPassword change required but no TTY available.\n')
<*.*.*.*> Failed to connect to the host via ssh: WARNING: Your password has expired.
Password change required but no TTY available.

Actual error : 

host_name | 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/ansible-$USER `\"&& mkdir /tmp/ansible-$USER/ansible-tmp-1655256382.78-15189-162690599720687 && echo ansible-tmp-1655256382.78-15189-162690599720687=\"` echo /tmp/ansible-$USER/ansible-tmp-1655256382.78-15189-162690599720687 `\" ), exited with result 1",
    "unreachable": true
===========
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Jaison
  • 1
0

This could happen mainly because on the Remote Server, there is no home directory present for the user.

The following steps resolved the issue for me -

  1. Log into the remote server

  2. switch to root

  3. If the user is linux_user from which Host (in my case Ansible) is trying to connect , then run following commands

    mkdir /home/linux_user

    chown linux_user:linux_user /home/linux_user

Sonal
  • 579
  • 5
  • 7