我想在整个剧本中只运行一次处理程序.
我尝试在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
Run Code Online (Sandbox Code Playgroud)
这是handlers/main.yml的内容:
- name: restart autofs
service:
name: autofs.service
state: restarted
Run Code Online (Sandbox Code Playgroud)
以下是通知处理程序的任务之一的示例:
- 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 …
Run Code Online (Sandbox Code Playgroud) 因此,我对 Linux 服务器序列号的 ansible“内置”事实进行了高低审视,而且如果没有自定义的 dmidecode ansible 模块,它似乎不可用。真的是这样吗?我觉得奇怪的是,由于有大量内置的 ansible 事实,序列号没有包括在内。
$ /usr/bin/ansible --version
ansible 2.4.2.0
config file = /home/user/.ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules',
u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.6.6 (r266:84292, Aug 9 2016, 06:11:56) [GCC 4.4.7
20120313 (Red Hat 4.4.7-17)]
Run Code Online (Sandbox Code Playgroud)