From 7fd2af1c5a33c05c3fdbfa216e83c3435fac3546 Mon Sep 17 00:00:00 2001 From: Allar Viik Date: Tue, 14 Nov 2023 16:13:03 +0200 Subject: [PATCH] Unified extra IPs configuration for netplan. nmcli & rc for `configure_networking` role --- .../core/roles/configure_networking/defaults/main.yml | 5 ----- .../roles/configure_networking/templates/netplan.yml | 11 ++++++++--- .../roles/configure_networking/templates/nmcli.sh | 4 ++-- .../roles/configure_networking/templates/rc.local | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/nova/core/roles/configure_networking/defaults/main.yml b/nova/core/roles/configure_networking/defaults/main.yml index 4e1e283f..e799c3f8 100644 --- a/nova/core/roles/configure_networking/defaults/main.yml +++ b/nova/core/roles/configure_networking/defaults/main.yml @@ -32,8 +32,3 @@ supported_connection_modes: # Routing options extra_routes: [] # Configure extra routes per interfaces. - -# Extra IPs -extra_ipv4: [] # Configure extra IPv4s per interfaces. -extra_ipv6: [] # Configure extra IPv6s per interfaces. -extra_ips: "{{ extra_ipv4 + extra_ipv6 }}" # Combined list of extra IPs per interfaces diff --git a/nova/core/roles/configure_networking/templates/netplan.yml b/nova/core/roles/configure_networking/templates/netplan.yml index 2fd7b56b..69fe0295 100644 --- a/nova/core/roles/configure_networking/templates/netplan.yml +++ b/nova/core/roles/configure_networking/templates/netplan.yml @@ -33,9 +33,14 @@ network: - "{{ ip_address.address }}" {% endif %} {% endfor %} - {% if extra_ips[ interface.network_id ] is defined %} - {% for extra_ip in extra_ips[ interface.network_id ] %} - - {{ extra_ip }} + {% if extra_ipv4[ interface.network_id ] is defined %} + {% for ipv4 in extra_ipv4[ interface.network_id ] %} + - {{ ipv4 }} + {% endfor %} + {% endif %} + {% if extra_ipv6[ interface.network_id ] is defined %} + {% for ipv6 in extra_ipv6[ interface.network_id ] %} + - {{ ipv6 }} {% endfor %} {% endif %} {% if (interface.addresses | selectattr("gateway", "!=", none)) or (extra_routes[ interface.network_id ] is defined) %} diff --git a/nova/core/roles/configure_networking/templates/nmcli.sh b/nova/core/roles/configure_networking/templates/nmcli.sh index cc66d17f..64054e07 100644 --- a/nova/core/roles/configure_networking/templates/nmcli.sh +++ b/nova/core/roles/configure_networking/templates/nmcli.sh @@ -43,14 +43,14 @@ fi {% endfor %} - {% if extra_ipv4 != [] %} + {% if extra_ipv4[ interface.network_id ] is defined %} # Adding extra ipv4 addresses for connection interface nmcli con modify $NMCLI_CONNECTION_NAME ipv4.method manual +ipv4.addresses "{{ extra_ipv4[ interface.network_id ] | join(', ') }}" {% endif %} - {% if extra_ipv6 != [] %} + {% if extra_ipv6[ interface.network_id ] is defined %} # Adding extra ipv6 addresses for connection interface nmcli con modify $NMCLI_CONNECTION_NAME ipv6.method manual +ipv6.addresses "{{ extra_ipv6[ interface.network_id ] | join(', ') }}" diff --git a/nova/core/roles/configure_networking/templates/rc.local b/nova/core/roles/configure_networking/templates/rc.local index c4cfa3df..49da34ca 100644 --- a/nova/core/roles/configure_networking/templates/rc.local +++ b/nova/core/roles/configure_networking/templates/rc.local @@ -19,13 +19,13 @@ ifconfig $INTERFACE_{{ interface_loop }}_NAME inet6 {{ ip_address.address | ansi {% endif %} {% endfor %} -{% if extra_ipv4 != [] %} +{% if extra_ipv4[ interface.network_id ] is defined %} {% for extra_ipv4 in extra_ipv4[interface.network_id] %} ifconfig $INTERFACE_{{ interface_loop }}_NAME inet {{ extra_ipv4 | ansible.utils.ipaddr('address') }} netmask {{ extra_ipv4 | ansible.utils.ipaddr('netmask') }} alias {% endfor %} {% endif %} -{% if extra_ipv6 != [] %} +{% if extra_ipv6[ interface.network_id ] is defined %} {% for extra_ipv6 in extra_ipv6[interface.network_id] %} ifconfig $INTERFACE_{{ interface_loop }}_NAME inet6 {{ extra_ipv6 | ansible.utils.ipaddr('address') }} prefixlen {{ extra_ipv6 | ansible.utils.ipaddr('prefix') }} alias {% endfor %}