Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement workaround for router name lookup bug #27

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions roles/os_networks/tasks/networks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 :(
ansible.builtin.include_tasks: router_workaround.yml
with_items: "{{ os_networks_routers }}"
when: item.state | default('present') == 'present'

Expand Down
32 changes: 32 additions & 0 deletions roles/os_networks/tasks/router_workaround.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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:
sd109 marked this conversation as resolved.
Show resolved Hide resolved
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
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) }}"