Skip to content

Commit

Permalink
reset network service: use systemd module directly
Browse files Browse the repository at this point in the history
  • Loading branch information
VannTen committed Dec 10, 2024
1 parent 9b523bc commit e3eca66
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions roles/reset/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,6 @@
- network

- name: Reset | Restart network
become: true
vars:
network_services:
- NetworkManager
- systemd-networkd
- networking
- network
when:
- ansible_os_family not in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
- reset_restart_network | bool
Expand All @@ -429,16 +422,19 @@
- network
block:
- name: Gather active network services
# noqa command-instead-of-module
command: systemctl is-active {{ item }}
loop: "{{ 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.item }}"
name: "{{ item }}"
state: restarted
loop: "{{ service_status.results }}"
when: item.stdout == "active"
loop: "{{ service_status.results | selectattr('status.ActiveState', '==', 'active') | map(attribute='item') }}"

0 comments on commit e3eca66

Please sign in to comment.