Compare commits

...

4 Commits

3 changed files with 64 additions and 21 deletions

View File

@@ -1,8 +1,13 @@
---
# handlers file for systemd-timesyncd
- name: restart network-manager
become: true
service:
name: NetworkManager.service
# handlers file for network-manager
- name: Restart NetworkManager
systemd:
name: NetworkManager
state: restarted
listen: network-manager configuration changed
- name: Reboot the system
reboot:
reboot_timeout: 180
async: 0
poll: 0
listen: "Notify the reboot handler"

View File

@@ -0,0 +1,34 @@
---
- name: Check and remove udev rules
block:
- name: Find udev rules files
find:
paths: /etc/udev/rules.d
patterns: "*-cloud-ifupdown.rules"
register: udev_rules_to_remove
- name: Get dynamically defined file path from udev rule
command: grep -oP 'RUN\+="\K[^"]*' "{{ run.path }}"
with_items: "{{ udev_rules_to_remove.files }}"
register: dynamic_file_paths
loop_control:
loop_var: run
- name: Remove dynamically defined file
file:
path: "{{ runf.stdout }}"
state: absent
with_items: "{{ dynamic_file_paths.results }}"
when: runf.stdout is defined and runf.stdout != ''
loop_control:
loop_var: runfile
- name: Remove udev rules
file:
path: "{{ rule.path }}"
state: absent
with_items: "{{ udev_rules_to_remove.files | default([]) }}"
when: udev_rules_to_remove.matched > 0
loop_control:
loop_var: rule
notify: Notify the reboot handler

View File

@@ -1,8 +1,6 @@
---
# tasks file for network-manager
- name: "apt install NetworkManager {{ nm_version }} "
become: true
apt:
name: "network-manager{{ nm_version }}"
default_release: "{{ ansible_distribution_release }}-backports"
@@ -10,7 +8,6 @@
update_cache: true
- name: config globally managed devices
become: true
template:
src: "conf.d/10-globally-managed-devices.j2"
dest: "{{ globally_managed_devices_path }}"
@@ -18,27 +15,34 @@
group: root
mode: 0644
when: globally_managed_devices is true
notify: network-manager configuration changed
- name: cleanup globally managed devices
become: true
file:
path: "{{ globally_managed_devices_path }}"
state: absent
when: not globally_managed_devices
notify: Restart NetworkManager
- name: Include tasks for checking and removing udev rules
include_tasks: check_udev_rules.yml
- name: Configure NetworkManager
become: true
community.general.nmcli:
conn_name: "{{ net_item.con_name }}"
ifname: "{{ net_item.ifname }}"
type: "{{ net_item.type }}"
ip4: "{{ net_item.ip4 }}"
gw4: "{{ net_item.gw4 | default('') }}"
dns4: "{{ net_item.dns4 | default([]) }}"
method6: "{{ net_item.method6 | default('auto') }}"
autoconnect: "{{ connection.autoconnect | default('true') }}"
conn_name: "{{ connection.con_name }}"
ifname: "{{ connection.ifname }}"
type: "{{ connection.type }}"
ip4: "{{ connection.ip4 | default('') }}"
gw4: "{{ connection.gw4 | default('') }}"
dns4: "{{ connection.dns4 | default([]) }}"
routes4: "{{ connection.routes4 | default([]) }}"
method4: "{{ connection.method4 | default('manual') }}"
method6: "{{ connection.method6 | default('auto') }}"
state: present
with_items: "{{ network }}"
loop_control:
loop_var: net_item
notify: network-manager configuration changed
loop_var: connection
notify: Restart NetworkManager
- name: Notify the reboot handler
meta: flush_handlers