From 7b8b4446022a4be8c5147c368b7ff30901308376 Mon Sep 17 00:00:00 2001 From: Elachance Date: Thu, 17 Aug 2017 12:30:38 -0700 Subject: [PATCH] Fix logic in os_nova_host_aggregate module (#23191) * Fix logic in os_nova_host_aggregate module Fix logic around adding availability zone to metadata and comparing existing host list to parameter host list. Previously, when no availability zone was defined, an empty availability zone was being appended to metadata. This was causing 'empty named availability zone' errors when running the module against an already existing host aggregate with no availability zone. This was fixed by only appending availability zone to metadata if it is not an empty parameter. Also added set() casting when comparing existing and new host lists. Previously, if existing host list was not in the same order as the host list in the .yml parameter file the module would consider this a change even if the two lists had the same entries. * Update os_nova_host_aggregate.py --- .../modules/cloud/openstack/os_nova_host_aggregate.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/openstack/os_nova_host_aggregate.py b/lib/ansible/modules/cloud/openstack/os_nova_host_aggregate.py index 84801ee903..aeffba3d18 100644 --- a/lib/ansible/modules/cloud/openstack/os_nova_host_aggregate.py +++ b/lib/ansible/modules/cloud/openstack/os_nova_host_aggregate.py @@ -88,10 +88,12 @@ from distutils.version import StrictVersion def _needs_update(module, aggregate): new_metadata = (module.params['metadata'] or {}) - new_metadata['availability_zone'] = module.params['availability_zone'] + + if module.params['availability_zone'] is not None: + new_metadata['availability_zone'] = module.params['availability_zone'] if ((module.params['name'] != aggregate.name) or - (module.params['hosts'] is not None and module.params['hosts'] != aggregate.hosts) or + (module.params['hosts'] is not None and set(module.params['hosts']) != set(aggregate.hosts)) or (module.params['availability_zone'] is not None and module.params['availability_zone'] != aggregate.availability_zone) or (module.params['metadata'] is not None and new_metadata != aggregate.metadata)): return True