Skip to content
Snippets Groups Projects
Unverified Commit 928fdf4b authored by Thomas Woerner's avatar Thomas Woerner Committed by GitHub
Browse files

Merge pull request #757 from rjeffman/templates_refactor

Update module templates to current practices.
parents 0d95b8eb 4df2cab4
Branches
Tags
No related merge requests found
...@@ -36,6 +36,7 @@ short description: Manage FreeIPA $name ...@@ -36,6 +36,7 @@ short description: Manage FreeIPA $name
description: Manage FreeIPA $name and $name members description: Manage FreeIPA $name and $name members
extends_documentation_fragment: extends_documentation_fragment:
- ipamodule_base_docs - ipamodule_base_docs
- ipamoudle_base_docs.delete_continue
options: options:
name: name:
description: The list of $name name strings. description: The list of $name name strings.
...@@ -152,6 +153,7 @@ def main(): ...@@ -152,6 +153,7 @@ def main():
choices=["present", "absent"]), choices=["present", "absent"]),
), ),
supports_check_mode=True, supports_check_mode=True,
ipa_module_options=["delete_continue"]
) )
ansible_module._ansible_debug = True ansible_module._ansible_debug = True
...@@ -163,9 +165,14 @@ def main(): ...@@ -163,9 +165,14 @@ def main():
# present # present
PARAMETER1 = ansible_module.params_get("PARAMETER1") PARAMETER1 = ansible_module.params_get("PARAMETER1")
PARAMETER2 = ansible_module.params_get("PARAMETER2") # Note: some parameters must be compared in a case insensitive way,
# or are transliterated into its lowercase version by IPA API. For
# these parameters, use IPAAnsibleModule.params_get_lowercase.
PARAMETER2 = ansible_module.params_get_lowercase("PARAMETER2")
action = ansible_module.params_get("action") action = ansible_module.params_get("action")
delete_continue = ansible_module.params_get("delete_continue")
# state # state
state = ansible_module.params_get("state") state = ansible_module.params_get("state")
...@@ -202,6 +209,9 @@ def main(): ...@@ -202,6 +209,9 @@ def main():
# Make sure $name exists # Make sure $name exists
res_find = find_$name(ansible_module, name) res_find = find_$name(ansible_module, name)
# add/del lists
PARAMETER2_add, PARAMETER2_del = [], []
# Create command # Create command
if state == "present": if state == "present":
...@@ -228,19 +238,6 @@ def main(): ...@@ -228,19 +238,6 @@ def main():
PARAMETER2_add, PARAMETER2_del = gen_add_del_lists( PARAMETER2_add, PARAMETER2_del = gen_add_del_lists(
PARAMETER2, res_find.get("member_PARAMETER2")) PARAMETER2, res_find.get("member_PARAMETER2"))
# Add members
if len(PARAMETER2_add) > 0:
commands.append([name, "$name_add_member",
{
"PARAMETER2": PARAMETER2_add,
}])
# Remove members
if len(PARAMETER2_del) > 0:
commands.append([name, "$name_remove_member",
{
"PARAMETER2": PARAMETER2_del,
}])
elif action == "member": elif action == "member":
if res_find is None: if res_find is None:
ansible_module.fail_json( ansible_module.fail_json(
...@@ -248,21 +245,17 @@ def main(): ...@@ -248,21 +245,17 @@ def main():
# Reduce add lists for PARAMETER2 # Reduce add lists for PARAMETER2
# to new entries only that are not in res_find. # to new entries only that are not in res_find.
if PARAMETER2 is not None and \
"API_PARAMETER2_NAME" in res_find:
PARAMETER2 = gen_add_list(
PARAMETER2, res_find["API_PARAMETER2_NAME"])
if PARAMETER2 is not None: if PARAMETER2 is not None:
commands.append([name, "$name_add_member", PARAMETER2_add = gen_add_list(
{ PARAMETER2, res_find.get("member_PARAMETER2"))
"PARAMETER2": PARAMETER2,
}])
elif state == "absent": elif state == "absent":
if action == "$name": if action == "$name":
if res_find is not None: if res_find is not None:
commands.append([name, "$name_del", {}]) commands.append(
[name, "$name_del", {"continue": delete_continue}]
)
elif action == "member": elif action == "member":
if res_find is None: if res_find is None:
...@@ -272,18 +265,29 @@ def main(): ...@@ -272,18 +265,29 @@ def main():
# Reduce del lists of member_host and member_hostgroup, # Reduce del lists of member_host and member_hostgroup,
# to the entries only that are in res_find. # to the entries only that are in res_find.
if PARAMETER2 is not None: if PARAMETER2 is not None:
PARAMETER2 = gen_intersection_list( PARAMETER2_del = gen_intersection_list(
PARAMETER2, res_find.get("API_PARAMETER2_NAME")) PARAMETER2, res_find.get("member_PARAMETER2"))
if PARAMETER2 is not None: else:
commands.append([name, "$name_remove_member", ansible_module.fail_json(msg="Unkown state '%s'" % state)
# Member management
# Add members
if PARAMETER2_add:
commands.append([name, "$name_add_member",
{ {
"PARAMETER2": PARAMETER2, "PARAMETER2": PARAMETER2_add,
}]) }])
else: # Remove members
ansible_module.fail_json(msg="Unkown state '%s'" % state)
if PARAMETER2_del:
commands.append([name, "$name_remove_member",
{
"PARAMETER2": PARAMETER2_del,
"continue": delete_continue,
}])
# Execute commands # Execute commands
......
...@@ -36,6 +36,7 @@ short description: Manage FreeIPA $name ...@@ -36,6 +36,7 @@ short description: Manage FreeIPA $name
description: Manage FreeIPA $name description: Manage FreeIPA $name
extends_documentation_fragment: extends_documentation_fragment:
- ipamodule_base_docs - ipamodule_base_docs
- ipamodule_base_docs.delete_continue
options: options:
name: name:
description: The list of $name name strings. description: The list of $name name strings.
...@@ -124,6 +125,7 @@ def main(): ...@@ -124,6 +125,7 @@ def main():
choices=["present", "absent"]), choices=["present", "absent"]),
), ),
supports_check_mode=True, supports_check_mode=True,
ipa_module_options=["delete_continue"],
) )
ansible_module._ansible_debug = True ansible_module._ansible_debug = True
...@@ -135,7 +137,12 @@ def main(): ...@@ -135,7 +137,12 @@ def main():
# present # present
PARAMETER1 = ansible_module.params_get("PARAMETER1") PARAMETER1 = ansible_module.params_get("PARAMETER1")
PARAMETER2 = ansible_module.params_get("PARAMETER2") # Note: some parameters must be compared in a case insensitive way,
# or are transliterated into its lowercase version by IPA API. For
# these parameters, use IPAAnsibleModule.params_get_lowercase.
PARAMETER2 = ansible_module.params_get_lowercase("PARAMETER2")
delete_continue = ansible_module.params_get("delete_continue")
# state # state
state = ansible_module.params_get("state") state = ansible_module.params_get("state")
...@@ -188,7 +195,9 @@ def main(): ...@@ -188,7 +195,9 @@ def main():
elif state == "absent": elif state == "absent":
if res_find is not None: if res_find is not None:
commands.append([name, "$name_del", {}]) commands.append(
[name, "$name_del", {"continue": delete_continue}]
)
else: else:
ansible_module.fail_json(msg="Unkown state '%s'" % state) ansible_module.fail_json(msg="Unkown state '%s'" % state)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment