如何重新启动CentOS 7与Ansible? [英] How to reboot CentOS 7 with Ansible?
问题描述
我尝试重新启动在VirtualBox上运行 CentOS 7
的服务器。我使用这个任务:
I'm trying to reboot server running CentOS 7
on VirtualBox. I use this task:
- name: Restart server
command: /sbin/reboot
async: 0
poll: 0
ignore_errors: true
服务器重新启动,得到此错误:
Server is rebooted, but I get this error:
TASK: [common | Restart server] ***********************************************
fatal: [rolcabox] => SSH Error: Shared connection to 127.0.0.1 closed.
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.
FATAL: all hosts have already failed -- aborting
做错了?如何解决这个问题?
What am I doing wrong? How can I fix this?
推荐答案
你可能不会做任何真正的错误,只是/ sbin / reboot正在关闭下来服务器这么快,服务器正在拆除ansible使用的ansible之前ansible本身可以关闭它。因此,ansible报告错误,因为它看到SSH连接失败的意想不到的原因。
You're likely not doing anything truly wrong, it's just that /sbin/reboot is shutting down the server so quickly that the server is tearing down the SSH connection used by ansible before ansible itself can close it. As a result ansible is reporting an error because it sees the SSH connection failing for an unexpected reason.
你可能想要解决这个问题是从使用 / sbin / reboot
改为使用 / sbin / shutdown
。 shutdown命令允许您传递一个时间,当与 -r
开关组合时,它将执行重新启动而不是实际关闭。所以你可能想尝试这样的任务:
What you might want to do to get around this is to switch from using /sbin/reboot
to using /sbin/shutdown
instead. The shutdown command lets you pass a time, and when combined with the -r
switch it will perform a reboot rather than actually shutting down. So you might want to try a task like this:
- name: Restart server
command: /sbin/shutdown -r +1
async: 0
poll: 0
ignore_errors: true
$ b b
这将延迟服务器重新启动1分钟,但这样做应该给Ansible足够的时间来关闭SSH连接本身,从而避免您当前得到的错误。
This will delay the server reboot for 1 minute, but in doing so it should give Ansible enough time to to close the SSH connection itself, thereby avoiding the error that you're currently getting.
这篇关于如何重新启动CentOS 7与Ansible?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!