diff options
| author | Ahmed Abdelhalim <[email protected]> | 2025-08-11 00:32:09 +0200 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2025-08-11 16:29:32 +0200 |
| commit | bed8aaaeb0b63b2072fbd030d76f8f928432e7b8 (patch) | |
| tree | 72ef0ee02dfeb29e6f3971c6948e6d989b2dd441 | |
| parent | a05655e7c239b6f8167e36b141a1a3a060128d45 (diff) | |
Add network ipv4 configurations
| -rw-r--r-- | host_vars/archlinux.local.yml | bin | 29 -> 104 bytes | |||
| -rw-r--r-- | host_vars/archlinux.local.yml.example | 3 | ||||
| -rw-r--r-- | host_vars/rpi5.local.yml | bin | 29 -> 104 bytes | |||
| -rw-r--r-- | host_vars/rpi5.local.yml.example | 3 | ||||
| -rw-r--r-- | host_vars/ubuntu.local.yml | bin | 29 -> 104 bytes | |||
| -rw-r--r-- | host_vars/ubuntu.local.yml.example | 3 | ||||
| -rw-r--r-- | roles/network/meta/argument_specs.yml | 6 | ||||
| -rw-r--r-- | roles/network/tasks/main.yml | 8 | ||||
| -rw-r--r-- | roles/network/templates/eth0-connection.nmconnection.j2 | 7 | ||||
| -rw-r--r-- | roles/network/templates/wifi-connection.nmconnection.j2 | 6 |
10 files changed, 32 insertions, 4 deletions
diff --git a/host_vars/archlinux.local.yml b/host_vars/archlinux.local.yml Binary files differindex f8331458..779ac449 100644 --- a/host_vars/archlinux.local.yml +++ b/host_vars/archlinux.local.yml diff --git a/host_vars/archlinux.local.yml.example b/host_vars/archlinux.local.yml.example index d9e1a256..90185c62 100644 --- a/host_vars/archlinux.local.yml.example +++ b/host_vars/archlinux.local.yml.example @@ -1,2 +1,3 @@ --- -{} +network_ipv4_address: "10.0.0.201" +network_ipv4_gateway: "10.0.0.1" diff --git a/host_vars/rpi5.local.yml b/host_vars/rpi5.local.yml Binary files differindex f8331458..d2c64414 100644 --- a/host_vars/rpi5.local.yml +++ b/host_vars/rpi5.local.yml diff --git a/host_vars/rpi5.local.yml.example b/host_vars/rpi5.local.yml.example index d9e1a256..aa9af763 100644 --- a/host_vars/rpi5.local.yml.example +++ b/host_vars/rpi5.local.yml.example @@ -1,2 +1,3 @@ --- -{} +network_ipv4_address: "10.0.0.202" +network_ipv4_gateway: "10.0.0.1" diff --git a/host_vars/ubuntu.local.yml b/host_vars/ubuntu.local.yml Binary files differindex f8331458..596d68e9 100644 --- a/host_vars/ubuntu.local.yml +++ b/host_vars/ubuntu.local.yml diff --git a/host_vars/ubuntu.local.yml.example b/host_vars/ubuntu.local.yml.example index d9e1a256..defd152d 100644 --- a/host_vars/ubuntu.local.yml.example +++ b/host_vars/ubuntu.local.yml.example @@ -1,2 +1,3 @@ --- -{} +network_ipv4_address: "10.0.0.203" +network_ipv4_gateway: "10.0.0.1" diff --git a/roles/network/meta/argument_specs.yml b/roles/network/meta/argument_specs.yml index 33561c8d..32eed955 100644 --- a/roles/network/meta/argument_specs.yml +++ b/roles/network/meta/argument_specs.yml @@ -24,3 +24,9 @@ argument_specs: type: "list" description: "The network services to enable" elements: "str" + network_ipv4_address: + type: "str" + description: "The network IP(4) address to configure when provided" + network_ipv4_gateway: + type: "str" + description: "The network IP(4) gateway to configure when provided" diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index c45cb6da..f96b2c41 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -5,6 +5,14 @@ - name: "Include OS-specific tasks" ansible.builtin.include_tasks: "install-{{ ansible_os_family | lower }}.yml" +- name: "Validate network_ipv4_* params" + ansible.builtin.assert: + that: + - network_ipv4_address is defined + - network_ipv4_gateway is defined + fail_msg: "network_ipv4_address and network_ipv4_gateway are required together" + when: network_ipv4_address is defined or network_ipv4_gateway is defined + - name: "(chroot): Ensure network_services are enabled" ansible.builtin.command: cmd: "systemctl enable {{ item }}" diff --git a/roles/network/templates/eth0-connection.nmconnection.j2 b/roles/network/templates/eth0-connection.nmconnection.j2 index b5cbe276..ae573cf1 100644 --- a/roles/network/templates/eth0-connection.nmconnection.j2 +++ b/roles/network/templates/eth0-connection.nmconnection.j2 @@ -2,12 +2,17 @@ id=ethernet type=ethernet autoconnect=true -interface-name=eth0 [ethernet] [ipv4] +{% if network_ipv4_address is defined %} +method=manual +addresses={{ network_ipv4_address }} +gateway={{ network_ipv4_gateway }} +{% else %} method=auto +{% endif %} [ipv6] addr-gen-mode=default diff --git a/roles/network/templates/wifi-connection.nmconnection.j2 b/roles/network/templates/wifi-connection.nmconnection.j2 index 9fffbd12..deec573d 100644 --- a/roles/network/templates/wifi-connection.nmconnection.j2 +++ b/roles/network/templates/wifi-connection.nmconnection.j2 @@ -14,7 +14,13 @@ key-mgmt=wpa-psk psk={{ network_wifi_pass }} [ipv4] +{% if network_ipv4_address is defined %} +method=manual +addresses={{ network_ipv4_address }} +gateway={{ network_ipv4_gateway }} +{% else %} method=auto +{% endif %} [ipv6] addr-gen-mode=default |
