WIP
- уточнение кода для ipv4/ipv6
This commit is contained in:
50
tasks/connections.config.yml
Normal file
50
tasks/connections.config.yml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
---
|
||||||
|
- 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:
|
||||||
|
"{{ connection_params | combine(dynamic_params) }}"
|
||||||
|
with_items: "{{ network }}"
|
||||||
|
when: connection.type == 'ethernet'
|
||||||
|
loop_control:
|
||||||
|
loop_var: connection
|
||||||
|
vars:
|
||||||
|
connection_params:
|
||||||
|
autoconnect: "{{ connection.autoconnect | default('true') }}"
|
||||||
|
conn_name: "{{ connection.con_name }}"
|
||||||
|
ifname: "{{ connection.ifname | default(connection.con_name) }}"
|
||||||
|
type: "{{ connection.type }}"
|
||||||
|
state: "{{ connection.state | default('present') }}"
|
||||||
|
dynamic_params: >-
|
||||||
|
{{
|
||||||
|
dict(
|
||||||
|
ip4=connection.ip4 if connection.ip4 is defined else omit,
|
||||||
|
gw4=connection.gw4 if connection.gw4 is defined else omit,
|
||||||
|
dns4=connection.dns4 if connection.dns4 is defined else omit,
|
||||||
|
routes4=connection.routes4 if connection.routes4 is defined else omit,
|
||||||
|
method4=connection.method4 if connection.method4 is defined else 'disabled',
|
||||||
|
ip6=connection.ip6 if connection.ip6 is defined else omit,
|
||||||
|
gw6=connection.gw6 if connection.gw6 is defined else omit,
|
||||||
|
method6=connection.method6 if connection.method6 is defined else 'disabled'
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
notify: Restart NetworkManager
|
||||||
|
|
||||||
|
# notify:
|
||||||
|
# - networking changed
|
||||||
|
# - network-manager configuration changed
|
||||||
3
tasks/install-nm.debian-12.yml
Normal file
3
tasks/install-nm.debian-12.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
- name: Task specific to Debian 12
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "Executing tasks for Debian 12"
|
||||||
@@ -1,12 +1,27 @@
|
|||||||
---
|
---
|
||||||
# tasks file for network-manager
|
# tasks file for network-manager
|
||||||
- name: "apt install NetworkManager {{ nm_version }} "
|
#- name: "apt install NetworkManager {{ nm_version }} "
|
||||||
when: nm__skip_install is not true
|
# when: nm__skip_install is not true
|
||||||
apt:
|
# apt:
|
||||||
name: "network-manager{{ nm_version }}"
|
# name: "network-manager{{ nm_version }}"
|
||||||
default_release: "{{ ansible_distribution_release }}-backports"
|
# default_release: "{{ ansible_distribution_release }}-backports"
|
||||||
autoremove: true
|
# autoremove: true
|
||||||
update_cache: true
|
# update_cache: true
|
||||||
|
- name: Get OS and major version specific for NetworkManager installation
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
install_nm_tasks: >-
|
||||||
|
{%- if ansible_distribution == "Debian" and ansible_distribution_major_version == "12" -%}
|
||||||
|
install-nm.debian-12.yml
|
||||||
|
{%- elif ansible_distribution == "Debian" and ansible_distribution_major_version in ["10", "11"] -%}
|
||||||
|
install-nm.debian-10.yml
|
||||||
|
{%- elif ansible_distribution == "Ubuntu" -%}
|
||||||
|
install-nm.ubuntu.yml
|
||||||
|
{%- else -%}
|
||||||
|
install-nm.default.yml
|
||||||
|
{%- endif -%}
|
||||||
|
|
||||||
|
- name: Install NetworkManager for {{ ansible_distribution }} {{ ansible_distribution_major_version }}
|
||||||
|
ansible.builtin.include_tasks: "{{ install_nm_tasks }}"
|
||||||
|
|
||||||
- name: Enable service NetworkManager and ensure it is not masked
|
- name: Enable service NetworkManager and ensure it is not masked
|
||||||
ansible.builtin.systemd_service:
|
ansible.builtin.systemd_service:
|
||||||
@@ -14,8 +29,8 @@
|
|||||||
enabled: true
|
enabled: true
|
||||||
masked: no
|
masked: no
|
||||||
|
|
||||||
- name: config globally managed devices
|
- name: Configure globally managed devices to NM
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: "conf.d/10-globally-managed-devices.j2"
|
src: "conf.d/10-globally-managed-devices.j2"
|
||||||
dest: "{{ globally_managed_devices_path }}"
|
dest: "{{ globally_managed_devices_path }}"
|
||||||
owner: root
|
owner: root
|
||||||
@@ -24,51 +39,19 @@
|
|||||||
when: globally_managed_devices is true
|
when: globally_managed_devices is true
|
||||||
notify: Restart NetworkManager
|
notify: Restart NetworkManager
|
||||||
|
|
||||||
- name: cleanup globally managed devices
|
- name: Cleanup globally managed devices
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ globally_managed_devices_path }}"
|
path: "{{ globally_managed_devices_path }}"
|
||||||
state: absent
|
state: absent
|
||||||
when: not globally_managed_devices
|
when: not globally_managed_devices
|
||||||
notify: Restart NetworkManager
|
notify: Restart NetworkManager
|
||||||
|
|
||||||
- name: Include tasks for checking and removing udev rules
|
- name: Include tasks for checking and removing udev rules
|
||||||
include_tasks: check_udev_rules.yml
|
ansible.builtin.include_tasks: check_udev_rules.yml
|
||||||
|
|
||||||
- name: Configure NetworkManager [ type loopback ]
|
- name: Include tasks for managing connections
|
||||||
community.general.nmcli:
|
when: network is defined
|
||||||
autoconnect: "{{ connection.autoconnect | default('true') }}"
|
ansible.builtin.include_tasks: connections.config.yml
|
||||||
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 }}"
|
|
||||||
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('disabled') }}"
|
|
||||||
state: present
|
|
||||||
with_items: "{{ network }}"
|
|
||||||
when: connection.type == 'ethernet'
|
|
||||||
loop_control:
|
|
||||||
loop_var: connection
|
|
||||||
notify: Restart NetworkManager
|
|
||||||
|
|
||||||
- name: Notify the reboot handler
|
- name: Notify the reboot handler
|
||||||
meta: flush_handlers
|
meta: flush_handlers
|
||||||
@@ -1,2 +1,25 @@
|
|||||||
---
|
---
|
||||||
# vars file for network-manager
|
# vars file for network-manager
|
||||||
|
#network:
|
||||||
|
# - con_name: lo
|
||||||
|
# ifname: lo
|
||||||
|
# type: loopback
|
||||||
|
# ip4: "127.0.0.1/8,169.254.0.0/32"
|
||||||
|
# dns4: 77.88.8.8
|
||||||
|
# method4: manual
|
||||||
|
# method6: auto
|
||||||
|
# - con_name: ens160
|
||||||
|
# ifname: ens160
|
||||||
|
# type: ethernet
|
||||||
|
# ip4: 192.168.0.2/24
|
||||||
|
# gw4: 192.168.0.1
|
||||||
|
# method4: manual
|
||||||
|
# method6: disabled
|
||||||
|
|
||||||
|
template_connection_params:
|
||||||
|
ip4: "{{ connection.ip4 | default('null') }}"
|
||||||
|
gw4: "{{ connection.gw4 | default('null') }}"
|
||||||
|
dns4: "{{ connection.dns4 | default('null') }}"
|
||||||
|
routes4: "{{ connection.routes4 | default('null') }}"
|
||||||
|
method4: "{{ connection.method4 | default('disabled') }}"
|
||||||
|
method6: "{{ connection.method6 | default('disabled') }}"
|
||||||
Reference in New Issue
Block a user