本地主机中的 Ansible SSH 错误连接 [英] Ansible SSH ERROR connection in localhost
问题描述
当我针对本地主机启动剧本时出现此错误.
I have this error when I launch my playbook against the localhost host.
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
我的主机文件有这个配置:
And my hosts file have this config:
[local]
127.0.0.1
有什么问题?
谢谢!
推荐答案
Ansible 默认尝试通过 ssh 连接.对于本地主机,您应该将连接设置为 local
.
Ansible by default tries to connect through ssh. For localhost you should set the connection to local
.
你可以在调用剧本时定义这个:
You can define this when calling the playbook:
ansible-playbook playbook.yml --connection=local
在你的剧本中定义它:
- hosts: local
connection: local
或者,最好将其定义为仅用于 localhost/127.0.0.1 的主机变量.使用以下内容创建一个相对于您的剧本的文件 host_vars/127.0.0.1
:
Or, preferable, define it as a host var just for localhost/127.0.0.1. Create a file host_vars/127.0.0.1
relative to your playbook with this content:
ansible_connection: local
您也可以将其添加为库存中的组变量:
You also could add it as a group var in your inventory:
[local]
127.0.0.1
[local:vars]
ansible_connection=local
或作为主机变量:
[local]
127.0.0.1 ansible_connection=local
请参阅文档中的行为参数.
这篇关于本地主机中的 Ansible SSH 错误连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!