大网数据广告活动
服务器运维问答

Using ansible cli to restart servers return an error (while still restarting the servers)

· 52CE 我爱测

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 C…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-08-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。