summaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
authorAhmed Abdelhalim <[email protected]>2025-08-11 00:32:09 +0200
committerAhmed Abdelhalim <[email protected]>2025-08-11 16:29:32 +0200
commitbed8aaaeb0b63b2072fbd030d76f8f928432e7b8 (patch)
tree72ef0ee02dfeb29e6f3971c6948e6d989b2dd441 /roles
parenta05655e7c239b6f8167e36b141a1a3a060128d45 (diff)
Add network ipv4 configurations
Diffstat (limited to 'roles')
-rw-r--r--roles/network/meta/argument_specs.yml6
-rw-r--r--roles/network/tasks/main.yml8
-rw-r--r--roles/network/templates/eth0-connection.nmconnection.j27
-rw-r--r--roles/network/templates/wifi-connection.nmconnection.j26
4 files changed, 26 insertions, 1 deletions
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