Use code-level filtering instead of options_ignore_list for extra keys
- Add _filter_zone_config() function to extract only known keys from zone config - Remove options_ignore_list from argument_spec as it's unreliable across Ansible versions - Filter zones in main() before processing to allow any extra keys in YAML - More reliable approach for ignoring extra metadata keys (comment, type, etc.)
This commit is contained in:
@@ -884,6 +884,34 @@ def process_single_zone(module: AnsibleModule, zone_config: dict) -> dict:
|
||||
return manager.process_zone()
|
||||
|
||||
|
||||
def _filter_zone_config(zone_config: dict) -> dict:
|
||||
"""Filter zone configuration to extract only known keys.
|
||||
|
||||
This allows users to include extra metadata (comments, type, etc.) in their
|
||||
zone configuration without causing validation errors.
|
||||
"""
|
||||
filtered = {
|
||||
'name': zone_config.get('name'),
|
||||
'dns_server': zone_config.get('dns_server'),
|
||||
'records': []
|
||||
}
|
||||
|
||||
if 'records' in zone_config:
|
||||
for record in zone_config['records']:
|
||||
filtered_record = {
|
||||
'record': record.get('record'),
|
||||
'type': record.get('type'),
|
||||
'value': record.get('value'),
|
||||
}
|
||||
if 'ttl' in record:
|
||||
filtered_record['ttl'] = record['ttl']
|
||||
if 'state' in record:
|
||||
filtered_record['state'] = record['state']
|
||||
filtered['records'].append(filtered_record)
|
||||
|
||||
return filtered
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Main entry point for the module."""
|
||||
module = AnsibleModule(
|
||||
@@ -905,11 +933,9 @@ def main() -> None:
|
||||
value=dict(type='raw', required=True),
|
||||
ttl=dict(type='int'),
|
||||
state=dict(type='str', choices=['present', 'absent'], default='present')
|
||||
),
|
||||
options_ignore_list=['comment']
|
||||
)
|
||||
)
|
||||
),
|
||||
options_ignore_list=['type', 'comment']
|
||||
)
|
||||
),
|
||||
key_name=dict(type='str'),
|
||||
key_secret=dict(type='str', no_log=True),
|
||||
@@ -947,12 +973,15 @@ def main() -> None:
|
||||
|
||||
zones = module.params['zones']
|
||||
|
||||
# Filter zones to remove extra keys that might be present for documentation/metadata
|
||||
filtered_zones = [_filter_zone_config(zone) for zone in zones]
|
||||
|
||||
results = []
|
||||
overall_changed = False
|
||||
overall_failed = False
|
||||
|
||||
# Process zones sequentially
|
||||
for zone_config in zones:
|
||||
for zone_config in filtered_zones:
|
||||
result = process_single_zone(module, zone_config)
|
||||
results.append(result)
|
||||
if result.get('changed', False):
|
||||
|
||||
Reference in New Issue
Block a user