Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

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

What is the problem?

Thanks!

question from:https://stackoverflow.com/questions/37184699/ansible-ssh-error-connection-in-localhost

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Define it in your playbook:

- hosts: local
  connection: local

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

or as a host var:

[local]
127.0.0.1   ansible_connection=local

See Behavioral Parameters in docs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...