Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rolling restart with ansible handlers

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).

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.

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?

like image 834
Costi Ciudatu Avatar asked Nov 01 '14 01:11

Costi Ciudatu


1 Answers

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
like image 94
fnkr Avatar answered Oct 22 '22 01:10

fnkr