kubeasz/roles/chrony/tasks/main.yml

48 lines
1.3 KiB
YAML
Raw Normal View History

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
2019-06-29 18:10:51 +08:00
- name: apt 卸载 ntp
shell: 'apt remove -y ntp'
2019-07-16 22:47:53 +08:00
when: 'ansible_distribution in ["Ubuntu","Debian"]'
2019-06-29 18:10:51 +08:00
ignore_errors: true
- name: yum 卸载 ntp
shell: 'yum remove -y ntp'
2020-12-30 11:25:54 +08:00
when: 'ansible_distribution in ["CentOS","RedHat","Amazon","Aliyun"]'
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
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服务
shell: systemctl enable chronyd
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服务启动
shell: "systemctl is-active chronyd.service"
2021-04-06 20:03:42 +08:00
register: svc_status
until: '"active" in svc_status.stdout'
2021-04-06 20:03:42 +08:00
retries: 3
delay: 3
tags: restart_chronyd