我有一个angular色,从git更新我的项目的源代码,让我们把它命名为source_tree 。 Git仓库包含多个服务使用的源,所以如果检测到git的变化,我想重新启动在每个主机上使用该源的所有服务 。
即:
- git: repo=ssh://[email protected]/mylogin/hello.git dest=/home/mylogin/hello notify: restart everything dependent on source code
例如,我有angular色webapp , notification_service , celery 。 主机可以有任何一组这样的angular色,例如第一台服务器运行webapp ,第二台运行notification_service和celery 。 所有这些服务使用来自同一目录的源代码。
问题是:
我不能列出所有的处理程序notify如:
- git: repo=ssh://[email protected]/mylogin/hello.git dest=/home/mylogin/hello notify: - restart webapp - restart notification service - restart celery
因为如果我运行不具有所有angular色的playbook(或者即使主机不包括所有angular色),playbook也会失败,并显示错误:
ERROR: change handler (restart celery) is not defined
(即我有webapp.yml手册,其中包括source_tree和webappangular色,但不包括notification_service和celery 。)
而且没有办法忽略这个错误。
我不能创build具有相同名称的多个处理程序,只有一个(最后定义的)将生效。
如何克服这些限制?
我没有testing过这个angular色,但你可以尝试注册git任务的结果
- git: repo=ssh://[email protected]/mylogin/hello.git dest=/home/mylogin/hello register: gitrc
然后从每个angular色读取它。 例如,
在webapp/tasks/main.yml :
- supervisorctl: name=uwsgi state=restarted when: gitrc|changed
在celery/tasks/main.yml :
- supervisorctl: name=celery state=restarted when: gitrc|changed
当然,这些成为任务而不是处理程序。