dnsconfig: Fix management of forwarders.

If one tries to set a list of forwarders which include an already
existing forwarder, the existing forwarder is removed, and the list
of configured forwarders contain only the new ones.

This patch fixes this behavior by setting a union of the currently
available forwarders and the list of forwarders provided in the
playbook.

Tests were added to ensure this behavior.
This commit is contained in:
Rafael Guterres Jeffman
2022-01-19 09:54:16 -03:00
parent 04a8299be6
commit dead467982
2 changed files with 50 additions and 3 deletions

View File

@@ -144,8 +144,8 @@ def gen_args(module, state, dnsconfig, forwarders, forward_policy,
_args['idnsforwarders'] = ['']
elif state == 'present':
_args['idnsforwarders'] = [
fwd for fwd in _forwarders if fwd not in global_forwarders]
_args['idnsforwarders'] = \
list(set(list(_forwarders) + list(global_forwarders)))
# If no forwarders should be added, remove argument.
if not _args['idnsforwarders']:
del _args['idnsforwarders']