Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Ansible FreeIPA
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
Ansible FreeIPA
Commits
928fdf4b
Unverified
Commit
928fdf4b
authored
3 years ago
by
Thomas Woerner
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #757 from rjeffman/templates_refactor
Update module templates to current practices.
parents
0d95b8eb
4df2cab4
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
utils/templates/ipamodule+member.py.in
+36
-32
36 additions, 32 deletions
utils/templates/ipamodule+member.py.in
utils/templates/ipamodule.py.in
+11
-2
11 additions, 2 deletions
utils/templates/ipamodule.py.in
with
47 additions
and
34 deletions
utils/templates/ipamodule+member.py.in
+
36
−
32
View file @
928fdf4b
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
utils/templates/ipamodule.py.in
+
11
−
2
View file @
928fdf4b
...
@@ -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)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment