为了让新的敏感客户端添加时在Uchiwa出现检查, sensu-server和sensu-api需要重新启动。 目前有5个客户端和一个服务器。 每当一个新的敏感客户端被添加使用能力检查不出现在Uchiwa。 目前,我需要login到sensu服务器并重新启动服务。 如何使用ansible自动化?
根据这个文件有处理程序:
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"
可以使用notify来调用:
tasks: - name: restart everything command: echo "this task will restart the web services" notify: "restart web services"
这样如果configuration发生变化,服务将会重新启动,但是如何通知远程服务,例如从IP-A通知IP-B的服务?
( listen是一个2.2的新function,这是没有发表,所以我不会使用它)
通知就像一个普通的任务(除了它是由一个事件触发的),所以基本上你可以做这样的事情,这是一种丑陋的(和不安全的机器应该有SSH访问远程服务器),但应该pipe用。
handlers: - name: restart my remote service command: ssh user@myserver -- service restart myservice
但Ansible有一个更优雅的方式来处理这个与delegate_to
handlers: - name: restart my remote service service: name=myserver state=restarted delegate_to: myserver
它做什么,处理程序任务将在您已委派任务的服务器上执行。 然后按照您在问题中所述的方式插入到您的任务中。