From 0ed105fad14732adec2879995f16ca13a7bc4826 Mon Sep 17 00:00:00 2001 From: Scott Davidson Date: Mon, 26 Feb 2024 17:18:02 +0000 Subject: [PATCH 1/3] Implement workaround for router name lookup bug --- roles/os_networks/tasks/networks.yml | 36 ++++++++++++------- roles/os_networks/tasks/router_workaround.yml | 27 ++++++++++++++ 2 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 roles/os_networks/tasks/router_workaround.yml diff --git a/roles/os_networks/tasks/networks.yml b/roles/os_networks/tasks/networks.yml index 450fedc..ea352c4 100644 --- a/roles/os_networks/tasks/networks.yml +++ b/roles/os_networks/tasks/networks.yml @@ -62,19 +62,31 @@ - "{{ os_networks }}" - subnets +# - name: Ensure router is registered with neutron +# openstack.cloud.router: +# auth_type: "{{ os_networks_auth_type }}" +# auth: "{{ os_networks_auth }}" +# cacert: "{{ os_networks_cacert | default(omit) }}" +# cloud: "{{ os_networks_cloud | default(omit) }}" +# interface: "{{ os_networks_interface | default(omit, true) }}" +# name: "{{ item.name }}" +# interfaces: "{{ item.interfaces | default(omit) }}" +# network: "{{ item.network }}" +# external_fixed_ips: "{{ item.external_fixed_ips | default(omit) }}" +# project: "{{ item.project | default(omit) }}" +# state: "{{ item.state | default(omit) }}" +# loop: "{{ os_networks_routers }}" +# when: item.state | default('present') == 'present' + +# Workaround bug https://bugs.launchpad.net/ansible-collections-openstack/+bug/2049658 +# by looking up external network information using networks_info and then explicitly +# passing the network ID into the openstack.cloud.router. Remove this workaround and +# uncomment code above when bug is fixed. + - name: Ensure router is registered with neutron - openstack.cloud.router: - auth_type: "{{ os_networks_auth_type }}" - auth: "{{ os_networks_auth }}" - cacert: "{{ os_networks_cacert | default(omit) }}" - cloud: "{{ os_networks_cloud | default(omit) }}" - interface: "{{ os_networks_interface | default(omit, true) }}" - name: "{{ item.name }}" - interfaces: "{{ item.interfaces | default(omit) }}" - network: "{{ item.network | default(omit) }}" - external_fixed_ips: "{{ item.external_fixed_ips | default(omit) }}" - project: "{{ item.project | default(omit) }}" - state: "{{ item.state | default(omit) }}" + # Can't loop over blocks in Ansible so have to + # include separate tasks file instead :( + include_tasks: router_workaround.yml with_items: "{{ os_networks_routers }}" when: item.state | default('present') == 'present' diff --git a/roles/os_networks/tasks/router_workaround.yml b/roles/os_networks/tasks/router_workaround.yml new file mode 100644 index 0000000..658d617 --- /dev/null +++ b/roles/os_networks/tasks/router_workaround.yml @@ -0,0 +1,27 @@ +# Workaround bug https://bugs.launchpad.net/ansible-collections-openstack/+bug/2049658 +# by looking up external network information using networks_info and then explicitly +# passing the network ID into the openstack.cloud.router's network field. + +# NOTE: When the item.network parameter is an ID then we are effectively querying a +# network by ID just to extract it's ID... but since the 'name' field of +# openstack.cloud.networks_info makes no distinction between names and IDs we can't +# really avoid this. + +- name: Fetch external network information + openstack.cloud.networks_info: + name: "{{ item.network }}" + register: _networks_query + +- name: Ensure router is registered with neutron + openstack.cloud.router: + auth_type: "{{ os_networks_auth_type }}" + auth: "{{ os_networks_auth }}" + cacert: "{{ os_networks_cacert | default(omit) }}" + cloud: "{{ os_networks_cloud | default(omit) }}" + interface: "{{ os_networks_interface | default(omit, true) }}" + name: "{{ item.name }}" + interfaces: "{{ item.interfaces | default(omit) }}" + network: "{{ _networks_query.networks[0].id }}" + external_fixed_ips: "{{ item.external_fixed_ips | default(omit) }}" + project: "{{ item.project | default(omit) }}" + state: "{{ item.state | default(omit) }}" From 7a5869ae2d872dcbdd36a4a09fe161eda4698cd1 Mon Sep 17 00:00:00 2001 From: Scott Davidson Date: Mon, 26 Feb 2024 17:26:14 +0000 Subject: [PATCH 2/3] Fix lints --- roles/os_networks/tasks/networks.yml | 4 ++-- roles/os_networks/tasks/router_workaround.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/os_networks/tasks/networks.yml b/roles/os_networks/tasks/networks.yml index ea352c4..5573eb3 100644 --- a/roles/os_networks/tasks/networks.yml +++ b/roles/os_networks/tasks/networks.yml @@ -80,13 +80,13 @@ # Workaround bug https://bugs.launchpad.net/ansible-collections-openstack/+bug/2049658 # by looking up external network information using networks_info and then explicitly -# passing the network ID into the openstack.cloud.router. Remove this workaround and +# passing the network ID into the openstack.cloud.router. Remove this workaround and # uncomment code above when bug is fixed. - name: Ensure router is registered with neutron # Can't loop over blocks in Ansible so have to # include separate tasks file instead :( - include_tasks: router_workaround.yml + ansible.builtin.include_tasks: router_workaround.yml with_items: "{{ os_networks_routers }}" when: item.state | default('present') == 'present' diff --git a/roles/os_networks/tasks/router_workaround.yml b/roles/os_networks/tasks/router_workaround.yml index 658d617..15bf3c1 100644 --- a/roles/os_networks/tasks/router_workaround.yml +++ b/roles/os_networks/tasks/router_workaround.yml @@ -3,7 +3,7 @@ # passing the network ID into the openstack.cloud.router's network field. # NOTE: When the item.network parameter is an ID then we are effectively querying a -# network by ID just to extract it's ID... but since the 'name' field of +# network by ID just to extract it's ID... but since the 'name' field of # openstack.cloud.networks_info makes no distinction between names and IDs we can't # really avoid this. From 1ffec35e3f95ce911ed93fca62030561f82d32df Mon Sep 17 00:00:00 2001 From: Scott Davidson Date: Tue, 27 Feb 2024 11:23:01 +0000 Subject: [PATCH 3/3] Pass additional fields through to network info query --- roles/os_networks/tasks/router_workaround.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/roles/os_networks/tasks/router_workaround.yml b/roles/os_networks/tasks/router_workaround.yml index 15bf3c1..f257ccd 100644 --- a/roles/os_networks/tasks/router_workaround.yml +++ b/roles/os_networks/tasks/router_workaround.yml @@ -10,6 +10,11 @@ - name: Fetch external network information openstack.cloud.networks_info: name: "{{ item.network }}" + auth_type: "{{ os_networks_auth_type }}" + auth: "{{ os_networks_auth }}" + cacert: "{{ os_networks_cacert | default(omit) }}" + cloud: "{{ os_networks_cloud | default(omit) }}" + interface: "{{ os_networks_interface | default(omit, true) }}" register: _networks_query - name: Ensure router is registered with neutron