尽管标准 ssh 正在运行,但 Ansible SSH 错误

jre*_*ger 6 ansible

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

ansible-playbook site.yml --limit localhost -vvvv
Run Code Online (Sandbox Code Playgroud)

我得到

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}
Run Code Online (Sandbox Code Playgroud)

如果我运行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
Run Code Online (Sandbox Code Playgroud)

udo*_*dan 7

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

创建一个host_vars/localhost与您的剧本相关的文件,内容如下:

---

ansible_connection: local

...
Run Code Online (Sandbox Code Playgroud)

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