Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible failed to transfer file to /command

Tags:

ansible

Recently I have been using ansible for a wide variety of automation. However, during testing for automatic tomcat6 restart on specific webserver boxes. I came across this new error that I can't seem to fix.

FAILED => failed to transfer file to /command 

Looking at documentation said its because of sftp-server not being in the sshd_config, however it is there.

Below is the command I am running to my webserver hosts.

ansible all -a "/usr/bin/sudo /etc/init.d/tomcat6 restart" -u user --ask-pass --sudo --ask-sudo-pass 

There is a .ansible hidden folder on each of the boxes so I know its making to them but its not executing the command.

Running -vvvv gives me this after:

EXEC ['sshpass', '-d10', 'ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o',    'ControlPersist=60s', '-o', 'ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'GSSAPIAuthentication=no', '-o', 'PubkeyAuthentication=no', '-o', 'User=user', '-o', 'ConnectTimeout=10', '10.10.10.103', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1400791384.19-262170576359689 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1400791384.19-262170576359689 && echo $HOME/.ansible/tmp/ansible-tmp-1400791384.19-262170576359689'"] 

then

10.10.10.103 | FAILED => failed to transfer file to /home/user/.ansible/tmp/ansible-tmp-1400791384.19-262170576359689/command 

Any help on this issue is much appreciated.

Thanks,


Edit:

To increase Googleability, here is another manifestation of the error that the chosen answer fixes.

Running the command ansible-playbook -i inventory hello_world.yml gives this warning for every host.

[WARNING]: sftp transfer mechanism failed on [host.example.com]. Use ANSIBLE_DEBUG=1 to see detailed information 

And when you rerun the command as ANSIBLE_DEBUG=1 ansible-playbook -i inventory hello_world.yml the only extra information you get is:

>>>sftp> put /var/folders/nc/htqkfk6j6h70hlxrr43rm4h00000gn/T/tmpxEWCe5 /home/ubuntu/.ansible/tmp/ansible-tmp-1487430536.22-28138635532013/command.py 
like image 347
Nvasion Avatar asked May 27 '14 21:05

Nvasion


2 Answers

do you have sftp subsystem enabled in sshd on the remote server? You can check it in /etc/sshd/sshd_config, the config file name depends on your distribution…anyway, look there for:

Subsystem      sftp    /usr/lib/ssh/sftp-server 

If this line is commented-out, the sftp is disabled. To fix it, you can either enable sftp, or change Ansible configuration. I prefer the Ansible configuration change, take a look at ansible.cfg and add/change:

[ssh_connection] scp_if_ssh=True 
like image 153
stibi Avatar answered Oct 02 '22 23:10

stibi


Without touching /etc/ansible/ansible.cfg

If only one host is affected, then this can be remedied on a per host basis in the hosts file as follows:

alias ansible_host=192.168.1.102 ansible_ssh_transfer_method=scp 

This solution requires ansible version 2.3 or higher.

[Source]

like image 27
Serge Stroobandt Avatar answered Oct 03 '22 00:10

Serge Stroobandt