在localhost中Ansible SSH ERROR连接

Mig*_*uel 27 ssh ansible ansible-playbook

当我针对localhost主机启动我的playbook时出现此错误.

TASK [setup] *******************************************************************
fatal: [127.0.0.1]: UNREACHABLE! => {"changed": false, "msg": "SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue", "unreachable": true}
to retry, use: --limit @deploy-test-env.retry

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=0    changed=0    unreachable=1    failed=0
Run Code Online (Sandbox Code Playgroud)

我的hosts文件有这个配置:

[local]
127.0.0.1
Run Code Online (Sandbox Code Playgroud)

问题是什么?

谢谢!

udo*_*dan 69

默认情况下,Ansible尝试通过ssh连接.对于localhost,您应该将连接设置为local.

你可以在调用playbook时定义它:

ansible-playbook playbook.yml --connection=local
Run Code Online (Sandbox Code Playgroud)

在你的剧本中定义它:

- hosts: local
  connection: local
Run Code Online (Sandbox Code Playgroud)

或者,最好将其定义为localhost/127.0.0.1的主机var.host_vars/127.0.0.1使用以下内容创建相对于您的剧本的文件:

ansible_connection: local
Run Code Online (Sandbox Code Playgroud)

您还可以将其添加为广告资源中的组var:

[local]
127.0.0.1

[local:vars]
ansible_connection=local
Run Code Online (Sandbox Code Playgroud)

或作为主机var:

[local]
127.0.0.1   ansible_connection=local
Run Code Online (Sandbox Code Playgroud)

请参阅文档中的行为参数.