如何使用 Ansible 重启 CentOS 7? [英] How to reboot CentOS 7 with Ansible?

查看:21
本文介绍了如何使用 Ansible 重启 CentOS 7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重启在 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 关闭服务器的速度如此之快,以至于服务器正在断开 SSH 连接在 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

这会延迟服务器重启 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.

这篇关于如何使用 Ansible 重启 CentOS 7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆