使用resmo.ntp配置ntp不同步
resmo.ntp支持debian系和redhat系,是目前比较好用的ntp配置. 建议就不要重复发明轮子了
在使用resmo.ntp的时候,发现使用其默认配置出来的机器连接不上ntp服务器.
ntpq> as
ind assid status conf reach auth condition last_event cnt
===========================================================
1 62663 943a yes yes none reject sys_peer 3
2 62664 963a yes yes none reject sys_peer 3
检查了role默认变量发现: ntp_config_listen 默认设置的是127.0.0.1
ntp_config_listen:
- '127.0.0.1'
ntp_config_listen修改为本机ip
此处需要改为被配置主机的IP.
在playbook中直接使用ansible 的fact变量即可,样例如下:
- hosts: zabbix*
become: true
vars:
ntp_config_server: [10.0.xxx,10.xxx]
ntp_config_listen: ["{{ ansible_default_ipv4.address }}"]
roles:
- role: resmo.ntp
检查客户端都ok了
zabbix01 | SUCCESS | rc=0 >>
synchronised to NTP server (10.0xxxx) at stratum 4
time correct to within 420 ms
polling server every 64 s
zabbix02 | SUCCESS | rc=0 >>
synchronised to NTP server (10.xxxx) at stratum 4
time correct to within 417 ms
polling server every 64 s
ansiblezabbix* -m shell -a ' echo as | ntpq'
zabbix01 | SUCCESS | rc=0 >>
ind assid status conf reach auth condition last_event cnt
===========================================================
1 10997 945a yes yes none candidate sys_peer 5
2 10998 963a yes yes none sys.peer sys_peer 3
zabbix02 | SUCCESS | rc=0 >>
ind assid status conf reach auth condition last_event cnt
===========================================================
1 21358 945a yes yes none candidate sys_peer 5
2 21359 963a yes yes none sys.peer sys_peer 3