From 951572bec1278b00373c9684decd114edf28ed1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Siemek?= Date: Thu, 1 Nov 2018 18:10:20 +0100 Subject: [PATCH] [backport 2.7] Check if `enabled_snat` is set in modules arguments (#46754) (#47807) * Check if `enabled_snat` is set in modules arguments (#46754) If `enabled_snat` is not set at all in module arguments but Neutron policy sets it by default in Openstack, then `os_router` will attempt to recreate otherwise perfectly good router. Follow up for https://github.com/ansible/ansible/issues/44432#issuecomment-428531031 (cherry picked from commit c2b7174d31ba4643606707ce64a0c6d3762a984e) * Add changelog entry --- changelogs/fragments/os_router_enable_snat_fix.yaml | 5 +++++ lib/ansible/modules/cloud/openstack/os_router.py | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/os_router_enable_snat_fix.yaml diff --git a/changelogs/fragments/os_router_enable_snat_fix.yaml b/changelogs/fragments/os_router_enable_snat_fix.yaml new file mode 100644 index 00000000000..bb4aa705b7f --- /dev/null +++ b/changelogs/fragments/os_router_enable_snat_fix.yaml @@ -0,0 +1,5 @@ +--- +bugfixes: + - Fixed an issue where ``os_router`` would attempt to recreate router, + because lack of ``enabled_snat`` parameter was treated as difference, + if default Neutron policy for snat is set. (https://github.com/ansible/ansible/issues/29903) diff --git a/lib/ansible/modules/cloud/openstack/os_router.py b/lib/ansible/modules/cloud/openstack/os_router.py index 643215028b3..44ec4462c23 100644 --- a/lib/ansible/modules/cloud/openstack/os_router.py +++ b/lib/ansible/modules/cloud/openstack/os_router.py @@ -227,8 +227,10 @@ def _needs_update(cloud, module, router, network, internal_subnet_ids, internal_ if router['admin_state_up'] != module.params['admin_state_up']: return True if router['external_gateway_info']: - if router['external_gateway_info'].get('enable_snat', True) != module.params['enable_snat']: - return True + # check if enable_snat is set in module params + if module.params['enable_snat'] is not None: + if router['external_gateway_info'].get('enable_snat', True) != module.params['enable_snat']: + return True if network: if not router['external_gateway_info']: return True