chore: ansible-lint review (almost done)

This commit is contained in:
Clément Désiles
2026-01-04 11:21:15 +01:00
parent 3e469fa25e
commit c79c445a23
67 changed files with 197 additions and 107 deletions
+32
View File
@@ -0,0 +1,32 @@
# net-persist
This role prevent the machine interface to change its name, thus to make unexpected changes to the network configuration. This rely on the mac address of the interface to map it to a static interface name.
If for some reason you might change your mac address (on a virtual machine for example), please update your inventory accordingly.
## Requirements
None
## Input variables
- `interface`:
```python
{
'mac_address': '02:a0:c9:8d:7e:b6',
'ip': '192.168.1.2',
'netmask': '255.255.255.0',
'gateway': '192.168.1.254',
'dns': ['1.1.1.1', '8.8.8.8'],
'name': 'lan0'
}
```
## License
MIT
## Author Information
Jokester <main@jokester.fr>
+19
View File
@@ -0,0 +1,19 @@
---
galaxy_info:
author: Jokester <main@jokester.fr>
description: Force the primary network interface to be 'lan0'
license: MIT
min_ansible_version: "2.10"
galaxy_tags:
- network
- persistent
- debian
- archlinux
- lan0
platforms:
- name: Debian
versions:
- all
- name: ArchLinux
versions:
- all
+35
View File
@@ -0,0 +1,35 @@
---
- name: Skip net-persist for non-ethernet interfaces
ansible.builtin.debug:
msg: "Skipping net-persist for {{ interface.name }} (type: {{ interface.type }})"
when: interface.type is defined and interface.type != 'ethernet'
- name: Process ethernet interface persistence
when: interface.type is not defined or interface.type == 'ethernet'
block:
- name: "Check interface rule for {{ interface.name }} ({{ interface.mac_address }})"
ansible.builtin.set_fact:
interface_original_name: "{{ ansible_facts.interfaces | select('in', ansible_facts) | map('extract', ansible_facts) | selectattr('pciid', 'defined') | selectattr('macaddress', 'equalto', interface.mac_address) | map(attribute='device') | first }}"
- name: What patch is needed
ansible.builtin.debug:
msg: >-
{%- if interface_original_name != interface.name -%}
iface {{ interface_original_name }} ({{ interface.mac_address }}) will be patched to {{ interface.name }}.
{%- else -%}
iface {{ interface.name }} is already set, no action needed.
{%- endif -%}
- name: Create persistent-net link file
when: interface_original_name != interface.name
ansible.builtin.template:
src: persistent-net.link.j2
dest: /etc/systemd/network/10-persistent-net-{{ interface.name }}.link
owner: root
group: root
mode: "0644"
- name: Notify a reboot is required
ansible.builtin.set_fact:
reboot_required: true
when: interface_original_name != interface.name
@@ -0,0 +1,10 @@
# -----------------------------------------------------------------------------------
# Forcing {{ interface.name }} to be predictable
# see https://wiki.debian.org/NetworkInterfaceNames#CUSTOM_SCHEMES_USING_.LINK_FILES
# see https://wiki.archlinux.org/title/Network_configuration#Change_interface_name
# -----------------------------------------------------------------------------------
[Match]
MACAddress={{ interface.mac_address }}
[Link]
Name={{ interface.name }}