I've been wondering what's the best way to trigger a series of actions
when a handler is notified.A good example for the need for this is deploying a web service from a
local checkout. What I do in this case:1. Prepare a tar file locally if any of the source files changed
Ideally, your development environment should build an updated tar when
code is updated. This does not seem to be a task for ansible, to me. Unless
maybe in an automated, asynchronous way, triggered by a commit, and
unrelated to your regular playbook.
2. Use the *copy* module to copy the tar file
register this task:
register: register_copy
Now comes the fun part - if the tar file was updated on the server, I would
like to trigger a sequence of actions. For instance:
Did you consider implementing those next steps as much as possible in an
idempotent way.?
1. Untar
when_changed: $register_copy
after this checking of the untar changed anything is a pain, a problem I
didn't fix myself yet. Writing a 'zip/unzip/tar/untar' module would be
nice, but I'm not sure this is easy to do in an idempotent way.
2. Reinstall requirements for the new package
This really needs to be done in an idempotent way so it's not a problem to
rerun this steps several times.
3. Restart the appropriate services
This should be a handler.
4. Possibly some more actions on the web front-end or accompanying services
Possibly this, too.
Implementing this as a trigger/subscribe linked list is extremely tedious
and verbose. What would have made this a lot simpler is something like this:- name: copy tar
action: copy src=... dest=...
notify: reinstall
...
handlers:
- name: reinstall
include: reinstall_tasks.yml
It would indeed be nice to *group handlers*, though.
And as handlers are basically just tasks, why not be able to include a task
(list)?
Serge