使用 ansible 处理程序滚动重启 [英] Rolling restart with ansible handlers

查看:52
本文介绍了使用 ansible 处理程序滚动重启的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个 ansible playbook,安装一个服务并在自上次运行后发生任何变化时重新启动它(或多或少是 ansible 处理程序的规范用例).

I want to run an ansible playbook that installs a service and restarts it if anything has changed since the last run (more or less the canonical use-case for ansible handlers).

但我想要一个不同的并行性来安装而不是重新启动:我想一次安装在所有主机上,但是,如果service-restart"处理程序被调用,我希望它运行一次在 X 台主机上.

But I want a different parallelism for installing than for restarting: I want to install on all the hosts at a time but, if the "service-restart" handler gets invoked I want that to run on X hosts at a time.

我知道这对于具有不同 serial 值的不同剧本是可能的.但是如果我走这条路,我看不到如何使用处理程序.而且我无法负担像 2 这样具有 serial 值的单一剧本,因为大多数情况下该服务不会发生任何变化.

I know this is possible with different plays that have different serial values. But I can't see how I could make use of handlers if I go this route. And I can't afford to have a single playbook with a serial value like 2, as most of the time nothing will change for that service.

处理程序可以跨多个播放吗?或者有没有其他方法可以在没有黑客的情况下做到这一点?

Can the handlers span multiple plays? Or is there any other way to do this without hacks?

推荐答案

Ansible 2.9.0 引入了 throttle 关键字,可在任务、块或播放级别使用以限制数量允许的工人数(最多指定的叉或串行设置).

Ansible 2.9.0 introduced the throttle keyword, which can be used at the task, block, or play level to limit the number of workers (up to the specified forks or serial setting) allowed.

例如,这可以用来一个一个地重启数据库集群中的节点:

For example, this can be used to restart nodes in a database cluster one by one:

- name: Restart MySQL
  throttle: 1
  service:
    name: mysql
    state: restarted

这篇关于使用 ansible 处理程序滚动重启的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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