diff options
Diffstat (limited to 'roles/network')
| -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 |
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 |
