问题原文
原帖链接 · 030 · CC BY-SA 4.0
- name: be sure check-http.rb is copied
copy:
src: /tmp/sensu-plugins-http/bin/check-http.rb
dest: /etc/sensu/plugins/check-http.rb
remote_src: true
owner: sensu
group: sensu
mode: 0500
notify:
- restart sensu-api
- restart sensu-client
- restart sensu-server
- name: be sure check_websites.json is copied
template:
src: check_websites.j2
dest: "{{ sensu_conf_d }}/check_websites.json"
register: check_websites_config
notify:
- restart sensu-api
- restart sensu-client
- restart sensu-server
Instead of repeating:
notify:
- restart sensu-api
- restart sensu-client
- restart sensu-server
is it possible to make it concise, e.g.:
notify:
- restart sensu-services
Expected answer
@knowhy suggested this solution, but I am looking for a solution that is able to combine multiple restarts in a handler and not in the tasks directory
已采纳解答
原帖链接 · Henrik Pingel · CC BY-SA 4.0
There is no such functionality available in Ansible as of today.
There are some more or less ugly workarounds (as linked in the question) which I won't repeat here.
The best solution I can think of would be to write a handler which combines these tasks. Assuming that the handler in the question asked, just restarts services, a with_items loop could be used like this:
- name: restart sensu-services
service:
name: "{{ item }}"
state: restarted
with_items:
- sensu-api
- sensu-client
- sensu-server
There is an open feature request to support blocks as handlers. That would be a good abstraction for this usecase.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
