improve NTP package conflict handling (#12212)

Signed-off-by: bo.jiang <bo.jiang@daocloud.io>
This commit is contained in:
ERIK
2025-05-16 18:55:14 +08:00
committed by GitHub
parent bca5a4ce3b
commit e4c0c427a3
9 changed files with 53 additions and 24 deletions

View File

@@ -55,17 +55,6 @@ minimal_node_memory_mb: 1024
minimal_master_memory_mb: 1500
## NTP Settings
# Start the ntpd or chrony service and enable it at system boot.
ntp_enabled: false
# The package to install which provides NTP functionality.
# The default is ntp for most platforms, or chrony on RHEL/CentOS 7 and later.
# The ntp_package can be one of ['ntp', 'ntpsec', 'chrony']
ntp_package: >-
{% if ansible_os_family == "RedHat" -%}
chrony
{%- else -%}
ntp
{%- endif -%}
# Manage the NTP configuration file.
ntp_manage_config: false

View File

@@ -1,12 +1,4 @@
---
- name: Ensure NTP package
package:
name:
- "{{ ntp_package }}"
state: present
when:
- not is_fedora_coreos
- not ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
- name: Disable systemd-timesyncd
service:

View File

@@ -770,3 +770,20 @@ system_upgrade_reboot: on-upgrade # never, always
# Enables or disables the scheduler plugins.
scheduler_plugins_enabled: false
## NTP Settings
# Start the ntpd or chrony service and enable it at system boot.
ntp_enabled: false
# TODO: Refactor NTP package selection to integrate with the general package installation system
# instead of using a separate variable approach
# The package to install which provides NTP functionality.
# The default is ntp for most platforms, or chrony on RHEL/CentOS 7 and later.
# The ntp_package can be one of ['ntp', 'ntpsec', 'chrony']
ntp_package: >-
{% if ansible_os_family == "RedHat" -%}
chrony
{%- else -%}
ntp
{%- endif -%}

View File

@@ -65,14 +65,19 @@
tags:
- bootstrap_os
- name: Install packages requirements
- name: Manage packages
package:
name: "{{ pkgs | dict2items | selectattr('value', 'ansible.builtin.all') | map(attribute='key') }}"
state: present
name: "{{ item.packages | dict2items | selectattr('value', 'ansible.builtin.all') | map(attribute='key') }}"
state: "{{ item.state }}"
register: pkgs_task_result
until: pkgs_task_result is succeeded
retries: "{{ pkg_install_retries }}"
delay: "{{ retry_stagger | random + 3 }}"
when: not (ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"] or is_fedora_coreos)
loop:
- { packages: "{{ pkgs_to_remove }}", state: "absent", action_label: "remove" }
- { packages: "{{ pkgs }}", state: "present", action_label: "install" }
loop_control:
label: "{{ item.action_label }}"
tags:
- bootstrap_os

View File

@@ -1,4 +1,9 @@
---
pkgs_to_remove:
systemd-timesyncd:
- "{{ ntp_enabled }}"
- "{{ ntp_package == 'ntp' }}"
- "{{ ansible_os_family == 'Debian' }}"
pkgs:
apparmor:
- "{{ ansible_os_family == 'Debian' }}"
@@ -9,6 +14,9 @@ pkgs:
- "{{ ansible_distribution_major_version == '10' }}"
- "{{ 'k8s_cluster' in group_names }}"
bash-completion: []
chrony:
- "{{ ntp_enabled }}"
- "{{ ntp_package == 'chrony' }}"
conntrack:
- "{{ ansible_os_family in ['Debian', 'RedHat'] }}"
- "{{ ansible_distribution != 'openEuler' }}"
@@ -70,6 +78,12 @@ pkgs:
- "{{ 'k8s_cluster' in group_names }}"
nss:
- "{{ ansible_os_family == 'RedHat' }}"
ntp:
- "{{ ntp_enabled }}"
- "{{ ntp_package == 'ntp' }}"
ntpsec:
- "{{ ntp_enabled }}"
- "{{ ntp_package == 'ntpsec' }}"
openssl: []
python-apt:
- "{{ ansible_os_family == 'Debian' }}"