refactor(configuration): split network.yml into per-init-system dispatch files
This commit is contained in:
@@ -29,97 +29,9 @@
|
|||||||
- configuration_detected_interfaces | length > 0
|
- configuration_detected_interfaces | length > 0
|
||||||
fail_msg: Failed to detect any network interfaces.
|
fail_msg: Failed to detect any network interfaces.
|
||||||
|
|
||||||
- name: Configure NetworkManager profiles
|
- name: Configure networking
|
||||||
when: os not in ["alpine", "void"]
|
|
||||||
block:
|
|
||||||
- name: Copy NetworkManager keyfile per interface
|
|
||||||
vars:
|
|
||||||
configuration_iface: "{{ item }}"
|
|
||||||
configuration_iface_name: >-
|
|
||||||
{{
|
|
||||||
item.name
|
|
||||||
if (item.name | default('') | string | length) > 0
|
|
||||||
else (configuration_detected_interfaces[idx] | default('eth' ~ idx))
|
|
||||||
}}
|
|
||||||
configuration_net_uuid: "{{ ('LAN-' ~ idx ~ '-' ~ hostname) | ansible.builtin.to_uuid }}"
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: network.j2
|
|
||||||
dest: "/mnt/etc/NetworkManager/system-connections/LAN-{{ idx }}.nmconnection"
|
|
||||||
mode: "0600"
|
|
||||||
loop: "{{ system_cfg.network.interfaces }}"
|
|
||||||
loop_control:
|
|
||||||
index_var: idx
|
|
||||||
label: "LAN-{{ idx }}"
|
|
||||||
|
|
||||||
- name: Fix Ubuntu unmanaged devices
|
|
||||||
when: os in ["ubuntu", "ubuntu-lts"]
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: /mnt/etc/NetworkManager/conf.d/10-globally-managed-devices.conf
|
|
||||||
state: touch
|
|
||||||
mode: "0644"
|
|
||||||
|
|
||||||
- name: Configure Alpine networking
|
|
||||||
when: os == "alpine"
|
|
||||||
vars:
|
vars:
|
||||||
configuration_dns_list: "{{ system_cfg.network.dns.servers | default([]) }}"
|
configuration_network_task_map:
|
||||||
block:
|
alpine: network_alpine.yml
|
||||||
- name: Write Alpine network interfaces
|
void: network_void.yml
|
||||||
ansible.builtin.copy:
|
ansible.builtin.include_tasks: "{{ configuration_network_task_map[os] | default('network_nm.yml') }}"
|
||||||
dest: /mnt/etc/network/interfaces
|
|
||||||
mode: "0644"
|
|
||||||
content: |
|
|
||||||
auto lo
|
|
||||||
iface lo inet loopback
|
|
||||||
{% for iface in system_cfg.network.interfaces %}
|
|
||||||
{% set inv_name = iface.name | default('') | string %}
|
|
||||||
{% set det_name = configuration_detected_interfaces[loop.index0] | default('eth' ~ loop.index0) %}
|
|
||||||
{% set iface_name = inv_name if inv_name | length > 0 else det_name %}
|
|
||||||
{% set has_static = (iface.ip | default('') | string | length) > 0 %}
|
|
||||||
|
|
||||||
auto {{ iface_name }}
|
|
||||||
iface {{ iface_name }} inet {{ 'static' if has_static else 'dhcp' }}
|
|
||||||
{% if has_static %}
|
|
||||||
address {{ iface.ip }}/{{ iface.prefix }}
|
|
||||||
{% if iface.gateway | default('') | string | length %}
|
|
||||||
gateway {{ iface.gateway }}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
- name: Set Alpine DNS resolvers
|
|
||||||
when: configuration_dns_list | length > 0
|
|
||||||
ansible.builtin.copy:
|
|
||||||
dest: /mnt/etc/resolv.conf
|
|
||||||
mode: "0644"
|
|
||||||
content: |
|
|
||||||
{% for resolver in configuration_dns_list %}
|
|
||||||
nameserver {{ resolver }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
- name: Configure Void networking
|
|
||||||
when: os == "void"
|
|
||||||
vars:
|
|
||||||
configuration_dns_list: "{{ system_cfg.network.dns.servers | default([]) }}"
|
|
||||||
block:
|
|
||||||
- name: Write dhcpcd configuration
|
|
||||||
ansible.builtin.copy:
|
|
||||||
dest: /mnt/etc/dhcpcd.conf
|
|
||||||
mode: "0644"
|
|
||||||
content: |
|
|
||||||
{% for iface in system_cfg.network.interfaces %}
|
|
||||||
{% set inv_name = iface.name | default('') | string %}
|
|
||||||
{% set det_name = configuration_detected_interfaces[loop.index0] | default('eth' ~ loop.index0) %}
|
|
||||||
{% set iface_name = inv_name if inv_name | length > 0 else det_name %}
|
|
||||||
{% set has_static = (iface.ip | default('') | string | length) > 0 %}
|
|
||||||
{% if has_static %}
|
|
||||||
interface {{ iface_name }}
|
|
||||||
static ip_address={{ iface.ip }}/{{ iface.prefix }}
|
|
||||||
{% if iface.gateway | default('') | string | length %}
|
|
||||||
static routers={{ iface.gateway }}
|
|
||||||
{% endif %}
|
|
||||||
{% if loop.index0 == 0 and configuration_dns_list | length > 0 %}
|
|
||||||
static domain_name_servers={{ configuration_dns_list | join(' ') }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
|
|||||||
37
roles/configuration/tasks/network_alpine.yml
Normal file
37
roles/configuration/tasks/network_alpine.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
---
|
||||||
|
- name: Write Alpine network interfaces
|
||||||
|
vars:
|
||||||
|
configuration_dns_list: "{{ system_cfg.network.dns.servers | default([]) }}"
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /mnt/etc/network/interfaces
|
||||||
|
mode: "0644"
|
||||||
|
content: |
|
||||||
|
auto lo
|
||||||
|
iface lo inet loopback
|
||||||
|
{% for iface in system_cfg.network.interfaces %}
|
||||||
|
{% set inv_name = iface.name | default('') | string %}
|
||||||
|
{% set det_name = configuration_detected_interfaces[loop.index0] | default('eth' ~ loop.index0) %}
|
||||||
|
{% set iface_name = inv_name if inv_name | length > 0 else det_name %}
|
||||||
|
{% set has_static = (iface.ip | default('') | string | length) > 0 %}
|
||||||
|
|
||||||
|
auto {{ iface_name }}
|
||||||
|
iface {{ iface_name }} inet {{ 'static' if has_static else 'dhcp' }}
|
||||||
|
{% if has_static %}
|
||||||
|
address {{ iface.ip }}/{{ iface.prefix }}
|
||||||
|
{% if iface.gateway | default('') | string | length %}
|
||||||
|
gateway {{ iface.gateway }}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
- name: Set Alpine DNS resolvers
|
||||||
|
vars:
|
||||||
|
configuration_dns_list: "{{ system_cfg.network.dns.servers | default([]) }}"
|
||||||
|
when: configuration_dns_list | length > 0
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /mnt/etc/resolv.conf
|
||||||
|
mode: "0644"
|
||||||
|
content: |
|
||||||
|
{% for resolver in configuration_dns_list %}
|
||||||
|
nameserver {{ resolver }}
|
||||||
|
{% endfor %}
|
||||||
26
roles/configuration/tasks/network_nm.yml
Normal file
26
roles/configuration/tasks/network_nm.yml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
- name: Copy NetworkManager keyfile per interface
|
||||||
|
vars:
|
||||||
|
configuration_iface: "{{ item }}"
|
||||||
|
configuration_iface_name: >-
|
||||||
|
{{
|
||||||
|
item.name
|
||||||
|
if (item.name | default('') | string | length) > 0
|
||||||
|
else (configuration_detected_interfaces[idx] | default('eth' ~ idx))
|
||||||
|
}}
|
||||||
|
configuration_net_uuid: "{{ ('LAN-' ~ idx ~ '-' ~ hostname) | ansible.builtin.to_uuid }}"
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: network.j2
|
||||||
|
dest: "/mnt/etc/NetworkManager/system-connections/LAN-{{ idx }}.nmconnection"
|
||||||
|
mode: "0600"
|
||||||
|
loop: "{{ system_cfg.network.interfaces }}"
|
||||||
|
loop_control:
|
||||||
|
index_var: idx
|
||||||
|
label: "LAN-{{ idx }}"
|
||||||
|
|
||||||
|
- name: Fix Ubuntu unmanaged devices
|
||||||
|
when: os in ["ubuntu", "ubuntu-lts"]
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /mnt/etc/NetworkManager/conf.d/10-globally-managed-devices.conf
|
||||||
|
state: touch
|
||||||
|
mode: "0644"
|
||||||
25
roles/configuration/tasks/network_void.yml
Normal file
25
roles/configuration/tasks/network_void.yml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
- name: Write dhcpcd configuration
|
||||||
|
vars:
|
||||||
|
configuration_dns_list: "{{ system_cfg.network.dns.servers | default([]) }}"
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /mnt/etc/dhcpcd.conf
|
||||||
|
mode: "0644"
|
||||||
|
content: |
|
||||||
|
{% for iface in system_cfg.network.interfaces %}
|
||||||
|
{% set inv_name = iface.name | default('') | string %}
|
||||||
|
{% set det_name = configuration_detected_interfaces[loop.index0] | default('eth' ~ loop.index0) %}
|
||||||
|
{% set iface_name = inv_name if inv_name | length > 0 else det_name %}
|
||||||
|
{% set has_static = (iface.ip | default('') | string | length) > 0 %}
|
||||||
|
{% if has_static %}
|
||||||
|
interface {{ iface_name }}
|
||||||
|
static ip_address={{ iface.ip }}/{{ iface.prefix }}
|
||||||
|
{% if iface.gateway | default('') | string | length %}
|
||||||
|
static routers={{ iface.gateway }}
|
||||||
|
{% endif %}
|
||||||
|
{% if loop.index0 == 0 and configuration_dns_list | length > 0 %}
|
||||||
|
static domain_name_servers={{ configuration_dns_list | join(' ') }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
Reference in New Issue
Block a user