enhance reset network service

Signed-off-by: KubeKyrie <shaolong.qin@daocloud.io>
pull/11678/head
KubeKyrie 2024-10-22 00:10:04 +08:00
parent e293a887da
commit 9b523bcd4a
2 changed files with 22 additions and 19 deletions

View File

@ -2,21 +2,5 @@
flush_iptables: true flush_iptables: true
reset_restart_network: 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 # crictl stop container grace period
cri_stop_containers_grace_period: 0 cri_stop_containers_grace_period: 0

View File

@ -414,12 +414,31 @@
- network - network
- name: Reset | Restart network - name: Reset | Restart network
service: become: true
name: "{{ reset_restart_network_service_name }}" vars:
state: restarted network_services:
- NetworkManager
- systemd-networkd
- networking
- network
when: when:
- ansible_os_family not in ["Flatcar", "Flatcar Container Linux by Kinvolk"] - ansible_os_family not in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
- reset_restart_network | bool - reset_restart_network | bool
tags: tags:
- services - services
- network - network
block:
- name: Gather active network services
# noqa command-instead-of-module
command: systemctl is-active {{ item }}
loop: "{{ network_services }}"
register: service_status
changed_when: false
ignore_errors: true
- name: Restart active network services
systemd:
name: "{{ item.item }}"
state: restarted
loop: "{{ service_status.results }}"
when: item.stdout == "active"