问题原文
原帖链接 · 030 · CC BY-SA 3.0
In order to let checks appear in Uchiwa when a new sensu-client is added, the sensu-server and sensu-api need to be restarted. At the moment there are 5 clients and one server. Everytime a new sensu-client is added using ansible the checks do not appear in Uchiwa. At the moment, I need to login to the sensu-server and restart the services. How to automate this using ansible?
According to this documentation there are handlers:
handlers:
- name: restart memcached
service: name=memcached state=restarted
listen: "restart web services"
- name: restart apache
service: name=apache state=restarted
listen: "restart web services"
that could be called using notify:
tasks:
- name: restart everything
command: echo "this task will restart the web services"
notify: "restart web services"
so that the service will be restarted if a change occurs in for example the config, but how to notify a remote service, e.g. notify service on IP-B from IP-A?
已采纳解答
原帖链接 · Baptiste Mille-Mathias · CC BY-SA 3.0
(listen is a 2.2 new feature which is not released as of writing, so I won't use it)
A notify is just like a regular tasks (or so) except it is triggered by an event, so basically you could do something like that, this is kind of ugly (and insecure as the machine should have ssh access to the remote servers) but should work.
handlers:
- name: restart my remote service
command: ssh user@myserver -- service restart myservice
But Ansible has a more elegant manner to handle this with delegate_to
handlers:
- name: restart my remote service
service: name=myserver state=restarted
delegate_to: myserver
What it does, it the handler task will be executed on the server(s) you've have delegate the task. and then plug-in to your task as you told in the question.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
