Hi all,
Is there any way to delegate handler execution on another host ?
Scenario : some client pushes part of a configuration (e.g. backup
client) to a server and triggers configuration rebuild (assemble) on the
server.
Of course the client in this scenario could issue assemble+delegate_to
but I would rather keep the whole logic contained in the right playbook,
and rebuild only when it is required to.
Thanks,
M
Excerpts from Michel Blanc's message of 2013-10-17 09:02:28 -0400:
Is there any way to delegate handler execution on another host ?
I think using 'delegate_to' on the handler itself will do what you
expect, but test it before you take my word for it.
Nice idea, I'll try it out.
Thanks Morgan.
M
Did that work for you, Michel? I have a similar situation, but I need to copy files to and delegate handlers to a group of servers. I have something like this:
- name: Deploy
hosts: source_box
tasks:
- name: copy files
command: rsync -az … {{ item }}:/dir
with_items: groups[‘destination_boxes’]
notify: service restart
handlers:
- name: service restart
service: name=service state=restarted
delegate_to: SERVER
If SERVER is, say, a literal IP address, it all works. But if I have more than one destination server, I need to make SERVER a variable, and that doesn’t work. Any ideas? Am I missing something?
Nathan
this should work:
delegate_to: “{{item}}”"with_items: groups[‘loadbalancers’]
or any list of servers
Thanks Brian, that should work well enough. What about the case where the rsync only changes files on a subset of the destination servers though? Is there a way to make sure that only the changed servers get restarted?
Nathan
Probably!
When you are delegating you could still but a “when” condition on it.
If you need to compare facts on other hosts you can use the “hostvars[hostname][‘foo_variable’]” method to get at them.