我想在整个剧本中只运行一次处理程序。只为整个剧本运行一次Ansible处理程序一次
我尝试使用包括在剧本文件下面的语句,但是这导致在处理程序被运行多次,一次为每个玩法:
- 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
这里是处理器/主要的内容。阳明:
- 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
如何让剧本仅在整个剧本中执行一次处理程序?
您的playbook看起来有点疯狂。这个剧本的总体思路是什么?为什么你在这里包括处理器?处理程序应该由任务通知,因此它是角色的一部分。 查看文档如何使用处理程序:https://docs.ansible.com/ansible/playbooks_intro.html。 另一种只运行一次特定任务的方法如下:https://docs.ansible.com/ansible/playbooks_delegation.html#run-once –
不确定wild是什么意思。剧本是一系列戏剧,其中有两个例子。我想为多个播放使用单个处理程序,并为整个Playbook执行一次。我希望这是有道理的。不需要只运行一次任务,只需要运行一次处理程序。 – user3155618
@techraf剧中有多个任务通知处理程序。我编辑了问题并添加了其中一项任务。 – user3155618