kubeasz/roles/chrony/tasks/main.yml

63 lines
2.0 KiB
YAML

- name: apt更新缓存刷新
apt: update_cache=yes cache_valid_time=72000
ignore_errors: true
when:
- 'ansible_distribution in ["Ubuntu","Debian"]'
- 'INSTALL_SOURCE != "offline"'
- name: apt 卸载 ntp
shell: 'apt remove -y ntp'
when: 'ansible_distribution in ["Ubuntu","Debian"]'
ignore_errors: true
- name: yum 卸载 ntp
shell: 'yum remove -y ntp'
when: 'ansible_distribution in ["CentOS","RedHat","Amazon"]'
args:
warn: false
ignore_errors: true
- name: 安装 chrony
package: name=chrony state=present
when: 'INSTALL_SOURCE != "offline"'
# 离线安装 chrony
- import_tasks: offline.yml
when: 'INSTALL_SOURCE == "offline"'
- block:
- name: 配置 chrony server
template: src=server-centos.conf.j2 dest=/etc/chrony.conf
when: 'ansible_distribution in ["CentOS","RedHat","Amazon"]'
- name: 配置 chrony server
template: src=server-ubuntu.conf.j2 dest=/etc/chrony/chrony.conf
when: 'ansible_distribution in ["Ubuntu","Debian"]'
- name: 启动 chrony server
service: name=chronyd state=restarted enabled=yes
when: 'ansible_distribution in ["CentOS","RedHat","Amazon"]'
- name: 启动 chrony server
service: name=chrony state=restarted enabled=yes
when: 'ansible_distribution in ["Ubuntu","Debian"]'
when: 'inventory_hostname == groups.chrony[0]'
- block:
- name: 配置 chrony client
template: src=client-centos.conf.j2 dest=/etc/chrony.conf
when: 'ansible_distribution in ["CentOS","RedHat","Amazon"]'
- name: 配置 chrony client
template: src=client-ubuntu.conf.j2 dest=/etc/chrony/chrony.conf
when: 'ansible_distribution in ["Ubuntu","Debian"]'
- name: 启动 chrony client
service: name=chronyd state=restarted enabled=yes
when: 'ansible_distribution in ["CentOS","RedHat","Amazon"]'
- name: 启动 chrony client
service: name=chrony state=restarted enabled=yes
when: 'ansible_distribution in ["Ubuntu","Debian"]'
when: 'inventory_hostname != groups.chrony[0]'