1
0
Fork 0
mirror of https://github.com/ansible-collections/ansible.posix.git synced 2026-02-04 08:01:49 +00:00

Refine the handling of exclusive options using mutually_exclusive

- Fixes #255

Signed-off-by: Hideki Saito <saito@fgrep.org>
This commit is contained in:
Hideki Saito 2021-11-29 17:49:26 +09:00
parent f17fda3162
commit 667ebef95c
3 changed files with 14 additions and 29 deletions

View file

@ -760,6 +760,10 @@ def main():
target=('zone',),
source=('permanent',),
),
mutually_exclusive=[
['icmp_block', 'icmp_block_inversion', 'service', 'port', 'port_forward', 'rich_rule',
'interface', 'masquerade', 'source', 'target']
],
)
permanent = module.params['permanent']
@ -816,33 +820,11 @@ def main():
if 'toaddr' in port_forward:
port_forward_toaddr = port_forward['toaddr']
modification_count = 0
if icmp_block is not None:
modification_count += 1
if icmp_block_inversion is not None:
modification_count += 1
if service is not None:
modification_count += 1
if port is not None:
modification_count += 1
if port_forward is not None:
modification_count += 1
if rich_rule is not None:
modification_count += 1
if interface is not None:
modification_count += 1
if masquerade is not None:
modification_count += 1
if source is not None:
modification_count += 1
if target is not None:
modification_count += 1
if modification_count > 1:
module.fail_json(
msg='can only operate on port, service, rich_rule, masquerade, icmp_block, icmp_block_inversion, interface or source at once'
)
elif (modification_count > 0) and (desired_state in ['absent', 'present']) and (target is None):
modification = False
if any([icmp_block, icmp_block_inversion, service, port, port_forward, rich_rule,
interface, masquerade, source, target]):
modification = True
if modification and desired_state in ['absent', 'present'] and target is None:
module.fail_json(
msg='absent and present state can only be used in zone level operations'
)
@ -1027,7 +1009,7 @@ def main():
msgs = msgs + transaction_msgs
''' If there are no changes within the zone we are operating on the zone itself '''
if modification_count == 0 and desired_state in ['absent', 'present']:
if not modification and desired_state in ['absent', 'present']:
transaction = ZoneTransaction(
module,