Skip to content

Commit

Permalink
Fix using the default network manager in reset.yml (#11678)
Browse files Browse the repository at this point in the history
* enhance reset network service

Signed-off-by: KubeKyrie <shaolong.qin@daocloud.io>

* reset network service: use systemd module directly

---------

Signed-off-by: KubeKyrie <shaolong.qin@daocloud.io>
Co-authored-by: Max Gautier <mg@max.gautier.name>
  • Loading branch information
KubeKyrie and VannTen authored Dec 24, 2024
1 parent 6c69ffe commit e7a5e3c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
16 changes: 0 additions & 16 deletions roles/reset/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 18 additions & 3 deletions roles/reset/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}"

0 comments on commit e7a5e3c

Please sign in to comment.