最近我一直在使用ansible进行各种自动化.但是,在特定Web服务器框上测试自动tomcat6重启期间.我遇到了这个我似乎无法解决的新错误.
FAILED => failed to transfer file to /command
Run Code Online (Sandbox Code Playgroud)
看文档说它是因为sftp-server不在sshd_config中,但是它就在那里.
下面是我运行到我的网络服务器主机的命令.
ansible all -a "/usr/bin/sudo /etc/init.d/tomcat6 restart" -u user --ask-pass --sudo --ask-sudo-pass
Run Code Online (Sandbox Code Playgroud)
每个盒子上都有一个.ansible隐藏文件夹,所以我知道它对它们的制作,但它没有执行命令.
运行-vvvv后给我这个:
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'"]
Run Code Online (Sandbox Code Playgroud)
然后
10.10.10.103 | FAILED => failed to transfer file to /home/user/.ansible/tmp/ansible-tmp-1400791384.19-262170576359689/command
Run Code Online (Sandbox Code Playgroud)
非常感谢您对此问题的任何帮助.
谢谢,
编辑:
为了提高Google可维护性,以下是所选答案修复错误的另一种表现形式.
运行该命令ansible-playbook -i inventory hello_world.yml
会为每个主机发出此警告.
[WARNING]: sftp transfer mechanism failed on [host.example.com]. Use ANSIBLE_DEBUG=1 to see detailed information
Run Code Online (Sandbox Code Playgroud)
当您重新运行命令时,ANSIBLE_DEBUG=1 ansible-playbook -i inventory hello_world.yml
您获得的唯一额外信息是:
>>>sftp> put /var/folders/nc/htqkfk6j6h70hlxrr43rm4h00000gn/T/tmpxEWCe5 /home/ubuntu/.ansible/tmp/ansible-tmp-1487430536.22-28138635532013/command.py
Run Code Online (Sandbox Code Playgroud)
sti*_*ibi 33
你在远程服务器上的sshd中启用了sftp子系统吗?您可以在/ etc/sshd/sshd_config中查看,配置文件名取决于您的发行版...无论如何,请查看:
Subsystem sftp /usr/lib/ssh/sftp-server
Run Code Online (Sandbox Code Playgroud)
如果此行已注释掉,则禁用sftp.要修复它,您可以启用sftp,也可以更改Ansible配置.我更喜欢Ansible配置更改,看一下ansible.cfg并添加/更改:
[ssh_connection]
scp_if_ssh=True
Run Code Online (Sandbox Code Playgroud)
/etc/ansible/ansible.cfg
如果只有一个主机受到影响,那么这是可以纠正的每个主机的基础上的中hosts
文件,如下所示:
alias ansible_host=192.168.1.102 ansible_ssh_transfer_method=scp
Run Code Online (Sandbox Code Playgroud)
此解决方案需要ansible
版本2.3或更高版本。
小智 5
尽管这确实可以追溯到14 年,当时@stibi最初解决了这个问题:
[ssh_connection]
scp_if_ssh=True
Run Code Online (Sandbox Code Playgroud)
它现在被 ansible.cfg 中的以下行取代,上面被@Serge Stroobandt称为内联主机选项:
[ssh_connection]
transfer_method = scp
Run Code Online (Sandbox Code Playgroud)
其中可能的值为scp
:
sftp = use sftp to transfer files
scp = use scp to transfer files
piped = use 'dd' over SSH to transfer files
smart = try sftp, scp, and piped, in that order [default]
Run Code Online (Sandbox Code Playgroud)
当您指定scp
而不是使用默认值时,您可以避免有关 的传输机制警告sftp
。
归档时间: |
|
查看次数: |
22111 次 |
最近记录: |