问题原文
原帖链接 · Buzut · CC BY-SA 3.0
I can successfully connect to my server with ssh. Nevertheless, when I try to execute a command through Ansible cli, it fails:
ansible en2 -a "/sbin/reboot" -vvv
Using /etc/ansible/ansible.cfg as config file
<en2> ESTABLISH SSH CONNECTION FOR USER: None
<en2> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/buzut/.ansible/cp/ansible-ssh-%h-%p-%r en2 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1470744750.87-182962282383475 `" && echo ansible-tmp-1470744750.87-182962282383475="` echo $HOME/.ansible/tmp/ansible-tmp-1470744750.87-182962282383475 `" ) && sleep 0'"'"''
<en2> PUT /tmp/tmpampMBF TO /root/.ansible/tmp/ansible-tmp-1470744750.87-182962282383475/command
<en2> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/buzut/.ansible/cp/ansible-ssh-%h-%p-%r '[en2]'
<en2> ESTABLISH SSH CONNECTION FOR USER: None
<en2> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/buzut/.ansible/cp/ansible-ssh-%h-%p-%r -tt en2 '/bin/sh -c '"'"'LANG=fr_FR.UTF-8 LC_ALL=fr_FR.UTF-8 LC_MESSAGES=fr_FR.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1470744750.87-182962282383475/command; rm -rf "/root/.ansible/tmp/ansible-tmp-1470744750.87-182962282383475/" > /dev/null 2>&1 && sleep 0'"'"''
en2 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh.",
"unreachable": true
}
已采纳解答
原帖链接 · techraf · CC BY-SA 3.0
Everything in your output looks correct.
Ansible establishes an SSH connection, runs its script (containing your command) and waits for its exit code.
However you order it to issue an /sbin/reboot command which reboots the server. The SSH connection is thus broken before the exit code is returned to the Ansible and Ansible reports the error.
The error message is actually a bit misleading, but it means the connection was broken.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
