我想在整个剧本中只运行一次处理程序。
我尝试在 playbook 文件的以下内容中使用 include 语句,但这导致处理程序运行多次,每次播放一次:
- name: Configure common config
hosts: all
become: true
vars:
OE: "{{ ansible_hostname[5] }}"
roles:
- { role: common }
handlers:
- include: handlers/main.yml
- name: Configure metadata config
hosts: metadata
become: true
vars:
OE: "{{ ansible_hostname[5] }}"
roles:
- { role: metadata }
handlers:
- include: handlers/main.yml
这是 handlers/main.yml 的内容:
- name: restart autofs
service:
name: autofs.service
state: restarted
以下是通知处理程序的任务之一的示例:
- name: Configure automount - /opt/local/xxx in /etc/auto.direct
lineinfile:
dest: /etc/auto.direct
regexp: "^/opt/local/xxx"
line: "/opt/local/xxx -acdirmin=0,acdirmax=0,rdirplus,rw,hard,intr,bg,retry=2 nfs_server:/vol/xxx"
notify: restart autofs
我怎样才能让剧本只为整个剧本执行一次处理程序?