summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--host_vars/archlinux.local.ymlbin29 -> 104 bytes
-rw-r--r--host_vars/archlinux.local.yml.example3
-rw-r--r--host_vars/rpi5.local.ymlbin29 -> 104 bytes
-rw-r--r--host_vars/rpi5.local.yml.example3
-rw-r--r--host_vars/ubuntu.local.ymlbin29 -> 104 bytes
-rw-r--r--host_vars/ubuntu.local.yml.example3
-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
10 files changed, 32 insertions, 4 deletions
diff --git a/host_vars/archlinux.local.yml b/host_vars/archlinux.local.yml
index f8331458..779ac449 100644
--- a/host_vars/archlinux.local.yml
+++ b/host_vars/archlinux.local.yml
Binary files differ
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
index f8331458..d2c64414 100644
--- a/host_vars/rpi5.local.yml
+++ b/host_vars/rpi5.local.yml
Binary files differ
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
index f8331458..596d68e9 100644
--- a/host_vars/ubuntu.local.yml
+++ b/host_vars/ubuntu.local.yml
Binary files differ
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