mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-08-05 14:24:48 +00:00
Allow processing of multiple names for deleting dnsforwardzones.
This commit is contained in:
@@ -134,7 +134,7 @@ def main():
|
|||||||
# general
|
# general
|
||||||
ipaadmin_principal=dict(type="str", default="admin"),
|
ipaadmin_principal=dict(type="str", default="admin"),
|
||||||
ipaadmin_password=dict(type="str", required=False, no_log=True),
|
ipaadmin_password=dict(type="str", required=False, no_log=True),
|
||||||
name=dict(type="str", aliases=["cn"], default=None,
|
name=dict(type="list", aliases=["cn"], default=None,
|
||||||
required=True),
|
required=True),
|
||||||
forwarders=dict(type='list', aliases=["idnsforwarders"],
|
forwarders=dict(type='list', aliases=["idnsforwarders"],
|
||||||
required=False),
|
required=False),
|
||||||
@@ -158,7 +158,7 @@ def main():
|
|||||||
"ipaadmin_principal")
|
"ipaadmin_principal")
|
||||||
ipaadmin_password = module_params_get(ansible_module,
|
ipaadmin_password = module_params_get(ansible_module,
|
||||||
"ipaadmin_password")
|
"ipaadmin_password")
|
||||||
name = module_params_get(ansible_module, "name")
|
names = module_params_get(ansible_module, "name")
|
||||||
action = module_params_get(ansible_module, "action")
|
action = module_params_get(ansible_module, "action")
|
||||||
forwarders = module_params_get(ansible_module, "forwarders")
|
forwarders = module_params_get(ansible_module, "forwarders")
|
||||||
forwardpolicy = module_params_get(ansible_module, "forwardpolicy")
|
forwardpolicy = module_params_get(ansible_module, "forwardpolicy")
|
||||||
@@ -166,6 +166,12 @@ def main():
|
|||||||
"skip_overlap_check")
|
"skip_overlap_check")
|
||||||
state = module_params_get(ansible_module, "state")
|
state = module_params_get(ansible_module, "state")
|
||||||
|
|
||||||
|
if state == 'present' and len(names) != 1:
|
||||||
|
ansible_module.fail_json(
|
||||||
|
msg="Only one dnsforwardzone can be added at a time.")
|
||||||
|
if state == 'absent' and len(names) < 1:
|
||||||
|
ansible_module.fail_json(msg="No name given.")
|
||||||
|
|
||||||
# absent stae means delete if the action is NOT member but update if it is
|
# absent stae means delete if the action is NOT member but update if it is
|
||||||
# if action is member then update an exisiting resource
|
# if action is member then update an exisiting resource
|
||||||
# and if action is not member then create a resource
|
# and if action is not member then create a resource
|
||||||
@@ -207,101 +213,102 @@ def main():
|
|||||||
ipaadmin_password)
|
ipaadmin_password)
|
||||||
api_connect()
|
api_connect()
|
||||||
|
|
||||||
# Make sure forwardzone exists
|
for name in names:
|
||||||
existing_resource = find_dnsforwardzone(ansible_module, name)
|
# Make sure forwardzone exists
|
||||||
|
existing_resource = find_dnsforwardzone(ansible_module, name)
|
||||||
|
|
||||||
if existing_resource is None and operation == "update":
|
if existing_resource is None and operation == "update":
|
||||||
# does not exist and is updating
|
# does not exist and is updating
|
||||||
# trying to update something that doesn't exist, so error
|
# trying to update something that doesn't exist, so error
|
||||||
ansible_module.fail_json(msg="""dnsforwardzone '%s' is not
|
ansible_module.fail_json(msg="""dnsforwardzone '%s' is not
|
||||||
valid""" % (name))
|
valid""" % (name))
|
||||||
elif existing_resource is None and operation == "del":
|
elif existing_resource is None and operation == "del":
|
||||||
# does not exists and should be absent
|
# does not exists and should be absent
|
||||||
# set command
|
# set command
|
||||||
command = None
|
command = None
|
||||||
# enabled or disabled?
|
# enabled or disabled?
|
||||||
is_enabled = "IGNORE"
|
|
||||||
elif existing_resource is not None and operation == "del":
|
|
||||||
# exists but should be absent
|
|
||||||
# set command
|
|
||||||
command = "dnsforwardzone_del"
|
|
||||||
# enabled or disabled?
|
|
||||||
is_enabled = "IGNORE"
|
|
||||||
elif forwarders is None:
|
|
||||||
# forwarders are not defined its not a delete, update state?
|
|
||||||
# set command
|
|
||||||
command = None
|
|
||||||
# enabled or disabled?
|
|
||||||
if existing_resource is not None:
|
|
||||||
is_enabled = existing_resource["idnszoneactive"][0]
|
|
||||||
else:
|
|
||||||
is_enabled = "IGNORE"
|
is_enabled = "IGNORE"
|
||||||
elif existing_resource is not None and operation == "update":
|
elif existing_resource is not None and operation == "del":
|
||||||
# exists and is updating
|
# exists but should be absent
|
||||||
# calculate the new forwarders and mod
|
# set command
|
||||||
# determine args
|
command = "dnsforwardzone_del"
|
||||||
if state != "absent":
|
# enabled or disabled?
|
||||||
forwarders = list(set(existing_resource["idnsforwarders"]
|
is_enabled = "IGNORE"
|
||||||
+ forwarders))
|
elif forwarders is None:
|
||||||
else:
|
# forwarders are not defined its not a delete, update state?
|
||||||
forwarders = list(set(existing_resource["idnsforwarders"])
|
# set command
|
||||||
- set(forwarders))
|
|
||||||
args = gen_args(forwarders, forwardpolicy,
|
|
||||||
skip_overlap_check)
|
|
||||||
if skip_overlap_check is not None:
|
|
||||||
del args['skip_overlap_check']
|
|
||||||
|
|
||||||
# command
|
|
||||||
if not compare_args_ipa(ansible_module, args, existing_resource):
|
|
||||||
command = "dnsforwardzone_mod"
|
|
||||||
else:
|
|
||||||
command = None
|
command = None
|
||||||
|
# enabled or disabled?
|
||||||
|
if existing_resource is not None:
|
||||||
|
is_enabled = existing_resource["idnszoneactive"][0]
|
||||||
|
else:
|
||||||
|
is_enabled = "IGNORE"
|
||||||
|
elif existing_resource is not None and operation == "update":
|
||||||
|
# exists and is updating
|
||||||
|
# calculate the new forwarders and mod
|
||||||
|
# determine args
|
||||||
|
if state != "absent":
|
||||||
|
forwarders = list(set(existing_resource["idnsforwarders"]
|
||||||
|
+ forwarders))
|
||||||
|
else:
|
||||||
|
forwarders = list(set(existing_resource["idnsforwarders"])
|
||||||
|
- set(forwarders))
|
||||||
|
args = gen_args(forwarders, forwardpolicy,
|
||||||
|
skip_overlap_check)
|
||||||
|
if skip_overlap_check is not None:
|
||||||
|
del args['skip_overlap_check']
|
||||||
|
|
||||||
# enabled or disabled?
|
# command
|
||||||
is_enabled = existing_resource["idnszoneactive"][0]
|
if not compare_args_ipa(ansible_module, args, existing_resource):
|
||||||
|
command = "dnsforwardzone_mod"
|
||||||
|
else:
|
||||||
|
command = None
|
||||||
|
|
||||||
elif existing_resource is None and operation == "add":
|
# enabled or disabled?
|
||||||
# does not exist but should be present
|
is_enabled = existing_resource["idnszoneactive"][0]
|
||||||
# determine args
|
|
||||||
args = gen_args(forwarders, forwardpolicy,
|
|
||||||
skip_overlap_check)
|
|
||||||
# set command
|
|
||||||
command = "dnsforwardzone_add"
|
|
||||||
# enabled or disabled?
|
|
||||||
is_enabled = "TRUE"
|
|
||||||
|
|
||||||
elif existing_resource is not None and operation == "add":
|
elif existing_resource is None and operation == "add":
|
||||||
# exists and should be present, has it changed?
|
# does not exist but should be present
|
||||||
# determine args
|
# determine args
|
||||||
args = gen_args(forwarders, forwardpolicy, skip_overlap_check)
|
args = gen_args(forwarders, forwardpolicy,
|
||||||
if skip_overlap_check is not None:
|
skip_overlap_check)
|
||||||
del args['skip_overlap_check']
|
# set command
|
||||||
|
command = "dnsforwardzone_add"
|
||||||
|
# enabled or disabled?
|
||||||
|
is_enabled = "TRUE"
|
||||||
|
|
||||||
# set command
|
elif existing_resource is not None and operation == "add":
|
||||||
if not compare_args_ipa(ansible_module, args, existing_resource):
|
# exists and should be present, has it changed?
|
||||||
command = "dnsforwardzone_mod"
|
# determine args
|
||||||
else:
|
args = gen_args(forwarders, forwardpolicy, skip_overlap_check)
|
||||||
command = None
|
if skip_overlap_check is not None:
|
||||||
|
del args['skip_overlap_check']
|
||||||
|
|
||||||
# enabled or disabled?
|
# set command
|
||||||
is_enabled = existing_resource["idnszoneactive"][0]
|
if not compare_args_ipa(ansible_module, args, existing_resource):
|
||||||
|
command = "dnsforwardzone_mod"
|
||||||
|
else:
|
||||||
|
command = None
|
||||||
|
|
||||||
# if command is set then run it with the args
|
# enabled or disabled?
|
||||||
if command is not None:
|
is_enabled = existing_resource["idnszoneactive"][0]
|
||||||
api_command(ansible_module, command, name, args)
|
|
||||||
changed = True
|
|
||||||
|
|
||||||
# does the enabled state match what we want (if we care)
|
# if command is set then run it with the args
|
||||||
if is_enabled != "IGNORE":
|
if command is not None:
|
||||||
if wants_enable and is_enabled != "TRUE":
|
api_command(ansible_module, command, name, args)
|
||||||
api_command(ansible_module, "dnsforwardzone_enable",
|
|
||||||
name, {})
|
|
||||||
changed = True
|
|
||||||
elif not wants_enable and is_enabled != "FALSE":
|
|
||||||
api_command(ansible_module, "dnsforwardzone_disable",
|
|
||||||
name, {})
|
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
# does the enabled state match what we want (if we care)
|
||||||
|
if is_enabled != "IGNORE":
|
||||||
|
if wants_enable and is_enabled != "TRUE":
|
||||||
|
api_command(ansible_module, "dnsforwardzone_enable",
|
||||||
|
name, {})
|
||||||
|
changed = True
|
||||||
|
elif not wants_enable and is_enabled != "FALSE":
|
||||||
|
api_command(ansible_module, "dnsforwardzone_disable",
|
||||||
|
name, {})
|
||||||
|
changed = True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
ansible_module.fail_json(msg=str(e))
|
ansible_module.fail_json(msg=str(e))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user