From c281a13b8e6c97d96e679bbeeb03380f1967a28e Mon Sep 17 00:00:00 2001 From: 135 Date: Fri, 19 Jan 2024 14:25:41 +0300 Subject: [PATCH] =?UTF-8?q?WIP.=20=D1=80=D0=B0=D0=B7=D0=BB=D0=B8=D1=87?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=82=D0=B8=D0=BF=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- defaults/main.yml | 1 + tasks/main.yml | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index fd8e265..b17f66d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,7 @@ --- # defaults file for network-manager nm_version: =1.42.* +nm__skip_install: false # force to configure conf.d/10-globally-managed-devices.conf globally_managed_devices: true globally_managed_devices_path: "/etc/NetworkManager/conf.d/10-globally-managed-devices.conf" diff --git a/tasks/main.yml b/tasks/main.yml index 33267e5..f067d56 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,12 +1,19 @@ --- # tasks file for network-manager - name: "apt install NetworkManager {{ nm_version }} " + when: nm__skip_install is not true apt: name: "network-manager{{ nm_version }}" default_release: "{{ ansible_distribution_release }}-backports" autoremove: true update_cache: true +- name: Enable service NetworkManager and ensure it is not masked + ansible.builtin.systemd_service: + name: NetworkManager + enabled: true + masked: no + - name: config globally managed devices template: src: "conf.d/10-globally-managed-devices.j2" @@ -15,6 +22,7 @@ group: root mode: 0644 when: globally_managed_devices is true + notify: Restart NetworkManager - name: cleanup globally managed devices file: @@ -26,7 +34,24 @@ - name: Include tasks for checking and removing udev rules include_tasks: check_udev_rules.yml -- name: Configure NetworkManager +- name: Configure NetworkManager [ type loopback ] + community.general.nmcli: + autoconnect: "{{ connection.autoconnect | default('true') }}" + conn_name: "{{ connection.con_name | default('lo') }}" + ifname: "{{ connection.ifname | default('lo') }}" + type: "{{ connection.type }}" + ip4: "{{ connection.ip4 | default('') }}" + dns4: "{{ connection.dns4 | default([]) }}" + method4: "{{ connection.method4 | default('manual') }}" + method6: "{{ connection.method6 | default('auto') }}" + state: present + with_items: "{{ network }}" + when: connection.type == 'loopback' + loop_control: + loop_var: connection + notify: Restart NetworkManager + +- name: Configure NetworkManager [ type ethernet ] community.general.nmcli: autoconnect: "{{ connection.autoconnect | default('true') }}" conn_name: "{{ connection.con_name }}" @@ -37,9 +62,10 @@ dns4: "{{ connection.dns4 | default([]) }}" routes4: "{{ connection.routes4 | default([]) }}" method4: "{{ connection.method4 | default('manual') }}" - method6: "{{ connection.method6 | default('auto') }}" + method6: "{{ connection.method6 | default('disabled') }}" state: present with_items: "{{ network }}" + when: connection.type == 'ethernet' loop_control: loop_var: connection notify: Restart NetworkManager