diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index 9e8ff037..ad1578a2 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -490,9 +490,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: + # 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: + 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: @@ -607,6 +619,9 @@ def issubset(self, item, objects): ''' for obj in objects: if isinstance(item, dict): + # Normalize MAC address + if 'mac' in item: + item['mac'] = item['mac'].replace('-', ':').lower() if all(entry in obj.items() for entry in item.items()): return True else: @@ -786,7 +801,15 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec): # check if test_obj_filter is empty copy passed obj_filter else: test_obj_filter = obj_filter - ib_obj = self.get_object(ib_obj_type, test_obj_filter.copy(), return_fields=list(ib_spec.keys())) + + return_fields = list(ib_spec.keys()) + if ib_obj_type == NIOS_HOST_RECORD: + ipv4addrs_return = ['ipv4addrs.use_for_ea_inheritance', 'ipv4addrs.ipv4addr', 'ipv4addrs.mac', 'ipv4addrs.configure_for_dhcp', 'ipv4addrs.host'] + ipv6addrs_return = ['ipv6addrs.use_for_ea_inheritance', 'ipv6addrs.ipv6addr', 'ipv6addrs.duid', 'ipv6addrs.configure_for_dhcp', 'ipv6addrs.host'] + 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 if old_ipv4addr_exists and (ib_obj is None or len(ib_obj) == 0): diff --git a/plugins/modules/nios_host_record.py b/plugins/modules/nios_host_record.py index 66f00549..da87df9b 100644 --- a/plugins/modules/nios_host_record.py +++ b/plugins/modules/nios_host_record.py @@ -66,6 +66,12 @@ required: true aliases: - address + use_for_ea_inheritance: + description: + - Set this to True when using this host address for EA inheritance. + The default value is False. + type: bool + required: false configure_for_dhcp: description: - Configure the host_record over DHCP instead of DNS, if user @@ -347,7 +353,8 @@ def main(): add=dict(type='bool', required=False), use_nextserver=dict(type='bool', required=False, aliases=['use_pxe']), nextserver=dict(required=False, aliases=['pxe']), - remove=dict(type='bool', required=False) + remove=dict(type='bool', required=False), + use_for_ea_inheritance=dict(type='bool', required=False) ) ipv6addr_spec = dict(