openstack.cloud.router should not remove existing interfaces

Bug #2107958 reported by Olaf Seibert
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ansible-collections-openstack
New
Undecided
Unassigned

Bug Description

If you specify a router but do not list any interfaces, and the router exists already, ansible should not remove the interfaces.

Example:

- name: "Configure edge router"
  environment: "{{ admin_env }}"
  delegate_to: localhost
  connection: local
  openstack.cloud.router:
    name: "edge router"
    state: "present"
    project: admin
    endpoint_type: internal
  run_once: true
  register: edge_router
  tags: ['router']

This is kind of similar to https://storyboard.openstack.org/#!/story/2010972 (where all interfaces are removed) but differs in that here we simply mention no interfaces at all. In the other bug it is mentioned that it is not possible to get a list of the existing interfaces. That is a good argument for having a way to leave the interfaces simply unchanged.

Revision history for this message
Olaf Seibert (oseibert-sys11) wrote (last edit ):

Also, the module doesn't support check mode. This is easily fixed. This will also supply some useful information about changes in diff mode. (It seems that launchpad renders tabs incorrectly so the indentation seems wrong) (and editing to add that remark made it even more wrong, I hope the idea remains somewhat clear)

--- /usr/lib/python3/dist-packages/ansible_collections/openstack/cloud/plugins/modules/router.py 2024-03-09 10:59:30.000000000 +0000
+++ openstack_cloud_router.py 2025-04-22 12:14:49.226717763 +0000
@@ -338,6 +338,7 @@
             'external_fixed_ips': 'network',
             'enable_snat': 'network',
         },
+ supports_check_mode=True,
     )

@@ -635,6 +642,8 @@

         if self.ansible.check_mode:
             # Check if the system state would be changed
+ kwargs = None
+ missing_internal_ports = None
             if state == 'absent' and router:
                 changed = True
             elif state == 'absent' and not router:
@@ -647,7 +656,7 @@
                 changed = self._needs_update(
                     router, kwargs, external_fixed_ips, to_add, to_remove,
                     missing_internal_ports)
- self.exit_json(changed=changed)
+ self.exit_json(changed=changed, kwargs=kwargs, to_add=to_add, to_remove=to_remove, router_ifs_internal=router_ifs_internal, external_fixed_ips=external_fixed_ips, missing_internal_ports=missing_internal_ports)

         if state == 'present':
             changed = False

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.