大网数据广告活动
服务器运维问答

Ansible SSH error although standard ssh is working

· 52CE 我爱测

I want to apply the playbook to the localhost ansible-playbook site.yml --limit localhost -vvvv and I get TASK [setup] ******************************************************************* <127.0.0.1> ESTABLISH SSH CONNECTION FOR U…

问题原文

原帖链接 · jreisinger · CC BY-SA 3.0

I want to apply the playbook to the localhost

ansible-playbook site.yml --limit localhost -vvvv

and I get

TASK [setup] *******************************************************************
<127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: root
<127.0.0.1> SSH: EXEC ssh -C -vvv -o ControlMaster=no -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -tt 127.0.0.1 '/bin/sh -c '"'"'mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1456926531.44-231334347877988 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1456926531.44-231334347877988 `"'"'"''
<127.0.0.1> PUT /tmp/tmpBYEsRj TO /root/.ansible/tmp/ansible-tmp-1456926531.44-231334347877988/setup
<127.0.0.1> SSH: EXEC sftp -b - -C -vvv -o ControlMaster=no -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 '[127.0.0.1]'
fatal: [127.0.0.1]: UNREACHABLE! => {"changed": false, "msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}

If I run ssh localhost it's working. Configuration:

$ cat ansible.cfg
[defaults]
hostfile = hosts
remote_user = root
host_key_checking = False

[ssh_connection]
control_path = /tmp
ssh_args = -o ControlMaster=no

已采纳解答

原帖链接 · udondan · CC BY-SA 3.0

You need to set the connection to local for localhost.

Create a file host_vars/localhost relative to your playbook with following content:

---

ansible_connection: local

...

Alternatively you could call ansible-playbook with the --connection=local option but it's good to have the above file in place in case you want to delegate a task to localhost.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。