Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

ansible SSH connection fail

I'm trying to run ansible role on multiple servers, but i get an error:

fatal: [192.168.0.10]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}

My /etc/ansible/hosts file looks like this:

192.168.0.10 ansible_sudo_pass='passphrase' ansible_ssh_user=user
192.168.0.11 ansible_sudo_pass='passphrase' ansible_ssh_user=user
192.168.0.12 ansible_sudo_pass='passphrase' ansible_ssh_user=user

I have no idea what's going on - everything looks fine - I can login via SSH, but ansible ping returns the same error.

The log from verbose execution:

<192.168.0.10> ESTABLISH SSH CONNECTION FOR USER: user <192.168.0.10> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=user -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.0.10 '/bin/sh -c '"'"'( umask 22 && mkdir -p "echo $HOME/.ansible/tmp/ansible-tmp-1463151813.31-156630225033829" && echo "echo $HOME/.ansible/tmp/ansible-tmp-1463151813.31-156630225033829" )'"'"''

Can you help me somehow? If I have to use ansible in local mode (-c local), then it's useless.

I've tried to delete ansible_sudo_pass and ansible_ssh_user, but it did'nt help.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

You need to change the ansible_ssh_pass as well or ssh key, for example I am using this in my inventory file:

192.168.33.100 ansible_ssh_pass=vagrant ansible_ssh_user=vagrant

After that I can connect to the remote host:

ansible all -i tests -m ping

With the following result:

192.168.33.100 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

Hope that help you.

EDIT: ansible_ssh_pass & ansible_ssh_user don't work in the latest version of Ansible. It has changed to ansible_user & ansible_pass


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...