diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index 2c1ecf09..39a698cd 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -351,7 +351,6 @@ def run(self, ib_obj_type, ib_spec): if not proposed_object.get('configure_for_dns') and proposed_object.get('view') == 'default' \ and ib_obj_type == NIOS_HOST_RECORD: del proposed_object['view'] - if ib_obj_ref: if len(ib_obj_ref) > 1: for each in ib_obj_ref: @@ -511,22 +510,21 @@ def run(self, ib_obj_type, ib_spec): result['changed'] = True if not self.module.check_mode and res is None: proposed_object = self.on_update(proposed_object, ib_spec) - self.update_object(ref, proposed_object) + res = self.update_object(ref, proposed_object) result['changed'] = True if ib_obj_type == NIOS_HOST_RECORD and res: # WAPI always reset the use_for_ea_inheritance for each update operation # Handle use_for_ea_inheritance flag changes for IPv4addr in a host record # Fetch the updated reference of host to avoid drift. - host_ref = self.connector.get_object(res) - - # Create a dictionary for quick lookups - ref_dict = {obj['ipv4addr']: obj['_ref'] for obj in host_ref['ipv4addrs']} - for proposed in proposed_object['ipv4addrs']: - ipv4addr = proposed['ipv4addr'] - if ipv4addr in ref_dict and 'use_for_ea_inheritance' in proposed: - self.update_object(ref_dict[ipv4addr], {'use_for_ea_inheritance': proposed['use_for_ea_inheritance']}) - + host_ref = self.connector.get_object(obj_type=str(res), return_fields=['ipv4addrs']) + if host_ref: + # Create a dictionary for quick lookups + ref_dict = {obj['ipv4addr']: obj['_ref'] for obj in host_ref['ipv4addrs']} + for proposed in proposed_object['ipv4addrs']: + ipv4addr = proposed['ipv4addr'] + if ipv4addr in ref_dict and 'use_for_ea_inheritance' in proposed: + self.update_object(ref_dict[ipv4addr], {'use_for_ea_inheritance': proposed['use_for_ea_inheritance']}) elif state == 'absent': if ref is not None: if 'ipv4addrs' in proposed_object: @@ -858,7 +856,6 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec): ] return_fields.extend(ipv4addrs_return) return_fields.extend(ipv6addrs_return) - ib_obj = self.get_object(ib_obj_type, test_obj_filter.copy(), return_fields=return_fields) # prevents creation of a new A record with 'new_ipv4addr' when A record with a particular 'old_ipv4addr' is not found