2021-04-06 20:03:42 +08:00
|
|
|
- name: prepare some dirs
|
|
|
|
file: name={{ item }} state=directory
|
|
|
|
with_items:
|
|
|
|
- "/etc/chrony"
|
|
|
|
- "/var/lib/chrony"
|
|
|
|
- "/var/log/chrony"
|
2018-08-17 09:18:55 +08:00
|
|
|
|
2023-05-02 17:11:18 +08:00
|
|
|
- name: 卸载 ntp
|
|
|
|
package: name=ntp state=absent
|
2019-06-29 18:10:51 +08:00
|
|
|
ignore_errors: true
|
2018-10-12 20:44:16 +08:00
|
|
|
|
2021-04-06 20:03:42 +08:00
|
|
|
- name: 下载二进制文件chronyd
|
|
|
|
copy: src={{ base_dir }}/bin/chronyd dest=/usr/sbin/chronyd mode=0755
|
2018-08-17 09:18:55 +08:00
|
|
|
|
2021-04-06 20:03:42 +08:00
|
|
|
- name: 创建chronyd的systemd unit文件
|
|
|
|
template: src=chronyd.service.j2 dest=/etc/systemd/system/chronyd.service
|
2018-08-17 09:18:55 +08:00
|
|
|
|
2021-04-06 20:03:42 +08:00
|
|
|
- name: 配置 chrony server
|
|
|
|
template: src=server.conf.j2 dest=/etc/chrony/chrony.conf
|
2019-05-27 20:02:02 +08:00
|
|
|
when: 'inventory_hostname == groups.chrony[0]'
|
2018-08-17 09:18:55 +08:00
|
|
|
|
2021-04-06 20:03:42 +08:00
|
|
|
- name: 配置 chrony client
|
|
|
|
template: src=client.conf.j2 dest=/etc/chrony/chrony.conf
|
|
|
|
when: 'inventory_hostname != groups.chrony[0]'
|
2018-08-17 09:18:55 +08:00
|
|
|
|
2021-04-06 20:03:42 +08:00
|
|
|
- name: 开机启用chronyd服务
|
2023-04-04 15:02:24 +08:00
|
|
|
shell: systemctl disable chronyd && systemctl enable chronyd
|
2021-04-06 20:03:42 +08:00
|
|
|
ignore_errors: true
|
2018-08-17 09:18:55 +08:00
|
|
|
|
2021-04-06 20:03:42 +08:00
|
|
|
- name: 开启chronyd服务
|
|
|
|
shell: systemctl daemon-reload && systemctl restart chronyd
|
|
|
|
ignore_errors: true
|
|
|
|
tags: restart_chronyd
|
|
|
|
|
|
|
|
- name: 以轮询的方式等待chronyd服务启动
|
2021-05-28 10:11:35 +08:00
|
|
|
shell: "systemctl is-active chronyd.service"
|
2021-04-06 20:03:42 +08:00
|
|
|
register: svc_status
|
2021-05-28 10:11:35 +08:00
|
|
|
until: '"active" in svc_status.stdout'
|
2021-04-06 20:03:42 +08:00
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
tags: restart_chronyd
|