尽管标准 ssh 可以运行,但 Ansible SSH 出现错误

尽管标准 ssh 可以运行,但 Ansible SSH 出现错误

我想将剧本应用到本地主机

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

我得到了

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}

如果我运行ssh localhost它就可以正常工作。配置:

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

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

答案1

您需要将连接设置local为 localhost。

host_vars/localhost创建与您的剧本相关的文件,其中包含以下内容:

---

ansible_connection: local

...

或者,您可以使用该选项调用 ansible-playbook,--connection=local但如果您想将任务委托给本地主机,最好将上述文件放在适当位置。

相关内容