Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to cancel a handler after it was notified?

I've got an enrvironment consisting of a stack of dockerized microapps, where some are dependant from others, linked to each other and communicate over http on the docker interface. My problem was that the docker-compose tracked only the docker-compose.yml file and recreated containers only when the docker-compose.yml has been changed. With ansible i can finally start tracking config files, that get mounted as volumes inside the containers, so they can be deployed from templates - which works fantastically.

Before ansible I used to run:

 docker-compose stop <app> && docker-compose rm -f <app> && docker-compose up -d

to refresh a single app when I knew the mounted file has been changed and the volumes needed to be refreshed.

I've defined multiple roles with the docker_service module for each app each one with its own handler that, when notified, runs the code above, to refresh that particular app.

The problem is, when multiple apps have their mounted files changed, ansible notifies each handler and each one gets executed which is not exactly the case i need as when the primary container (on which others depend) gets recreated the others don't need to because they have already been recreated, yet their handlers also are being executed. So my question is: is there a way to cancel a notified handler? I know about flush_handlers but that just executes notified handlers, not exactly what I need.

like image 313
CyborgWombat Avatar asked Mar 11 '23 06:03

CyborgWombat


1 Answers

You can use conditionals in handlers.
Use a flag variable to indicate that some handlers shouldn't execute.

- name: restart myapp1
  shell: docker ...
  when: not block_apps_restart
like image 133
Konstantin Suvorov Avatar answered Apr 06 '23 12:04

Konstantin Suvorov