Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using the default network manager in reset.yml #11678

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 22 additions & 3 deletions roles/reset/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,31 @@
- network

- name: Reset | Restart network
service:
name: "{{ reset_restart_network_service_name }}"
state: restarted
become: true
vars:
network_services:
- NetworkManager
- systemd-networkd
- networking
- network
Comment on lines +418 to +423
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop this var and just specify the list directly in the loop below.

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
# noqa command-instead-of-module
command: systemctl is-active {{ item }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the systemd module with only name to check for status.

systemd:
  name: <service>
register: service

service.status.ActivateState == 'active'

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 }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
loop: "{{ service_status.results }}"
loop: "{{ service_status.results | selectattr('status.ActiveState', '==', 'active') | map(attribute='item' }}"

+ drop the when

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @KubeKyrie

Would you please check it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks, I will check it.

when: item.stdout == "active"