From e7a5e3ca5ce21792282686625f3992d1bcc0641f Mon Sep 17 00:00:00 2001 From: kyrie <139965836+KubeKyrie@users.noreply.github.com> Date: Tue, 24 Dec 2024 22:50:11 +0800 Subject: [PATCH] Fix using the default network manager in reset.yml (#11678) * enhance reset network service Signed-off-by: KubeKyrie * reset network service: use systemd module directly --------- Signed-off-by: KubeKyrie Co-authored-by: Max Gautier --- roles/reset/defaults/main.yml | 16 ---------------- roles/reset/tasks/main.yml | 21 ++++++++++++++++++--- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/roles/reset/defaults/main.yml b/roles/reset/defaults/main.yml index 1e84da77dcc..293068cfd1a 100644 --- a/roles/reset/defaults/main.yml +++ b/roles/reset/defaults/main.yml @@ -2,21 +2,5 @@ flush_iptables: true reset_restart_network: true -reset_restart_network_service_name: >- - {% if ansible_os_family == "RedHat" -%} - {%- - if ansible_distribution_major_version | int >= 8 - or is_fedora_coreos or ansible_distribution in ["Fedora", "Kylin Linux Advanced Server", "TencentOS"] -%} - NetworkManager - {%- else -%} - network - {%- endif -%} - {%- elif ansible_distribution == "Ubuntu" - or (ansible_distribution == "Debian" and ansible_distribution_major_version | int == 12 ) -%} - systemd-networkd - {%- elif ansible_os_family == "Debian" -%} - networking - {%- endif %} - # crictl stop container grace period cri_stop_containers_grace_period: 0 diff --git a/roles/reset/tasks/main.yml b/roles/reset/tasks/main.yml index b68a1777b61..213bf833830 100644 --- a/roles/reset/tasks/main.yml +++ b/roles/reset/tasks/main.yml @@ -414,12 +414,27 @@ - network - name: Reset | Restart network - service: - name: "{{ reset_restart_network_service_name }}" - state: restarted when: - ansible_os_family not in ["Flatcar", "Flatcar Container Linux by Kinvolk"] - reset_restart_network | bool tags: - services - network + block: + - name: Gather active network services + systemd: + name: "{{ item }}" + loop: + - NetworkManager + - systemd-networkd + - networking + - network + register: service_status + changed_when: false + ignore_errors: true + + - name: Restart active network services + systemd: + name: "{{ item }}" + state: restarted + loop: "{{ service_status.results | selectattr('status.ActiveState', '==', 'active') | map(attribute='item') }}"