diff --git a/roles/chrony/defaults/main.yml b/roles/chrony/defaults/main.yml index bf33cd7..4d32fc7 100644 --- a/roles/chrony/defaults/main.yml +++ b/roles/chrony/defaults/main.yml @@ -9,3 +9,5 @@ ntp_servers: # 设置允许内部时间同步的网络段,比如"10.0.0.0/8",默认全部允许 local_network: "0.0.0.0/0" +# 离线安装 chrony (offline|online) +INSTALL_SOURCE: "offline" diff --git a/roles/chrony/tasks/main.yml b/roles/chrony/tasks/main.yml index f98b558..1745373 100644 --- a/roles/chrony/tasks/main.yml +++ b/roles/chrony/tasks/main.yml @@ -1,6 +1,6 @@ - name: apt更新缓存刷新 apt: update_cache=yes cache_valid_time=72000 - when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version|int >= 16 + when: ansible_distribution == "Ubuntu" and INSTALL_SOURCE != "offline" ignore_errors: true - name: 确保已卸载ntp @@ -8,6 +8,11 @@ - name: 安装 chrony package: name=chrony state=present + when: 'INSTALL_SOURCE != "offline"' + +# 离线安装 chrony +- import_tasks: offline.yml + when: 'INSTALL_SOURCE == "offline"' - block: - name: 配置 chrony server diff --git a/roles/chrony/tasks/offline.yml b/roles/chrony/tasks/offline.yml new file mode 100644 index 0000000..fb222f5 --- /dev/null +++ b/roles/chrony/tasks/offline.yml @@ -0,0 +1,27 @@ +# 离线安装 chrony +- name: 准备离线安装包目录 + file: name=/opt/kube/packages/chrony state=directory + +- block: + - name: 分发 chrony_xenial 离线包 + copy: + src: "{{ base_dir }}/down/packages/chrony_xenial.tar.gz" + dest: "/opt/kube/packages/chrony/chrony_xenial.tar.gz" + + - name: 安装 chrony_xenial 离线包 + shell: 'cd /opt/kube/packages/chrony && tar zxf chrony_xenial.tar.gz && \ + dpkg -i *.deb > /tmp/install_chrony.log 2>&1' + when: ansible_distribution_release == "xenial" + +- block: + - name: 分发 chrony_centos7 离线包 + copy: + src: "{{ base_dir }}/down/packages/chrony_centos7.tar.gz" + dest: "/opt/kube/packages/chrony/chrony_centos7.tar.gz" + + - name: 安装 chrony_centos7 离线包 + shell: 'cd /opt/kube/packages/chrony && tar zxf chrony_centos7.tar.gz && \ + rpm -Uvh --nodeps *.rpm > /tmp/install_chrony.log 2>&1' + when: + - 'ansible_distribution_major_version == "7"' + - 'ansible_distribution == "CentOS"'