使用Ansible安装ntp,我会通知处理程序以启动ntpd服务:
任务:
---
# roles/common/tasks/ntp.yml
- name: ntp | installing
yum: name=ntp state=latest
notify: start ntp
处理程序:
---
# roles/common/handlers/main.yml
- name: start ntp
service: name=ntpd state=started
如果服务尚未安装,Ansible 将安装并启动它。
如果服务已经安装,但没有运行,它不会通知处理程序:
任务的状态为
changed: false
。这意味着,如果服务已经存在于操作系统中,则无法启动它。
有什么好的实践可以确保服务已安装并处于运行状态吗?
PS:我可以这样做:
---
# roles/common/tasks/ntp.yml
- name: ntp | installing
yum: name=ntp state=latest
notify: start ntp
changed: true
但我不确定这是否是一个好的做法。