From eae8ce0848fd604e60382076f15989b90485f737 Mon Sep 17 00:00:00 2001 From: 135 Date: Mon, 11 Sep 2023 19:17:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D0=B4=20=D0=BF=D0=BE=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8E=20udev/r?= =?UTF-8?q?ules=20=D0=BC=D0=B5=D1=85=D0=B0=D0=BD=D0=B8=D0=B7=D0=BC=D0=B0?= =?UTF-8?q?=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=81=D0=B5=D1=82=D0=B5=D0=B2=D1=8B=D0=BC=D0=B8=20=D1=83?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=BE=D0=B9=D1=81=D1=82=D0=B2=D0=B0=D0=BC?= =?UTF-8?q?=D0=B8,=20=D1=85=D0=B0=D1=80=D0=B0=D0=BA=D1=82=D0=B5=D1=80?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B4=D0=BB=D1=8F=20noncloud=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D0=B7=D0=B0=20Debian=2011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/main.yml | 11 +++++++++++ tasks/check_udev_rules.yml | 33 +++++++++++++++++++++++++++++++++ tasks/main.yml | 26 ++++++++++++++++++++++---- 3 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 tasks/check_udev_rules.yml diff --git a/handlers/main.yml b/handlers/main.yml index 1dbad2d..4bfcde6 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,13 @@ --- # handlers file for network-manager +- name: Restart NetworkManager + systemd: + name: NetworkManager + state: restarted + +- name: Reboot the system + reboot: + reboot_timeout: 180 + async: 0 + poll: 0 + listen: "Notify the reboot handler" \ No newline at end of file diff --git a/tasks/check_udev_rules.yml b/tasks/check_udev_rules.yml new file mode 100644 index 0000000..f1711a3 --- /dev/null +++ b/tasks/check_udev_rules.yml @@ -0,0 +1,33 @@ +--- +- 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 diff --git a/tasks/main.yml b/tasks/main.yml index dae256e..c21952f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,7 +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" @@ -9,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 }}" @@ -19,8 +17,28 @@ when: globally_managed_devices is true - name: cleanup globally managed devices - become: true file: path: "{{ globally_managed_devices_path }}" state: absent - when: not globally_managed_devices \ No newline at end of file + when: not globally_managed_devices + +- name: Include tasks for checking and removing udev rules + include_tasks: check_udev_rules.yml + +- name: Configure NetworkManager + community.general.nmcli: + conn_name: "{{ connection.con_name }}" + ifname: "{{ connection.ifname }}" + type: "{{ connection.type }}" + ip4: "{{ connection.ip4 }}" + gw4: "{{ connection.gw4 | default('') }}" + dns4: "{{ connection.dns4 | default([]) }}" + method6: "{{ connection.method6 | default('auto') }}" + state: present + with_items: "{{ network }}" + loop_control: + loop_var: connection + notify: Restart NetworkManager + +- name: Notify the reboot handler + meta: flush_handlers \ No newline at end of file