mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-08-05 14:24:48 +00:00
Merge pull request #137 from t-woerner/ipagroup_pre_4_7_support
ipagroup: Properly support IPA versions 4.6 and RHEL-7
This commit is contained in:
@@ -142,7 +142,7 @@ Variable | Description | Required
|
|||||||
`nomembers` | Suppress processing of membership attributes. (bool) | no
|
`nomembers` | Suppress processing of membership attributes. (bool) | no
|
||||||
`user` | List of user name strings assigned to this group. | no
|
`user` | List of user name strings assigned to this group. | no
|
||||||
`group` | List of group name strings assigned to this group. | no
|
`group` | List of group name strings assigned to this group. | no
|
||||||
`service` | List of service name strings assigned to this group | no
|
`service` | List of service name strings assigned to this group. Only usable with IPA versions 4.7 and up. | no
|
||||||
`action` | Work on group or member level. It can be on of `member` or `group` and defaults to `group`. | no
|
`action` | Work on group or member level. It can be on of `member` or `group` and defaults to `group`. | no
|
||||||
`state` | The state to ensure. It can be one of `present` or `absent`, default: `present`. | yes
|
`state` | The state to ensure. It can be one of `present` or `absent`, default: `present`. | yes
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,9 @@ options:
|
|||||||
required: false
|
required: false
|
||||||
type: list
|
type: list
|
||||||
service:
|
service:
|
||||||
description: List of service names assigned to this group.
|
description:
|
||||||
|
- List of service names assigned to this group.
|
||||||
|
- Only usable with IPA versions 4.7 and up.
|
||||||
required: false
|
required: false
|
||||||
type: list
|
type: list
|
||||||
action:
|
action:
|
||||||
@@ -137,18 +139,18 @@ RETURN = """
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.ansible_freeipa_module import temp_kinit, \
|
from ansible.module_utils.ansible_freeipa_module import temp_kinit, \
|
||||||
temp_kdestroy, valid_creds, api_connect, api_command, compare_args_ipa
|
temp_kdestroy, valid_creds, api_connect, api_command, compare_args_ipa, \
|
||||||
|
api_check_param, module_params_get
|
||||||
|
|
||||||
|
|
||||||
def find_group(module, name):
|
def find_group(module, name):
|
||||||
_args = {
|
_args = {
|
||||||
"all": True,
|
"all": True,
|
||||||
"cn": to_text(name),
|
"cn": name,
|
||||||
}
|
}
|
||||||
|
|
||||||
_result = api_command(module, "group_find", to_text(name), _args)
|
_result = api_command(module, "group_find", name, _args)
|
||||||
|
|
||||||
if len(_result["result"]) > 1:
|
if len(_result["result"]) > 1:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
@@ -164,7 +166,7 @@ def gen_args(description, gid, nonposix, external, nomembers):
|
|||||||
if description is not None:
|
if description is not None:
|
||||||
_args["description"] = description
|
_args["description"] = description
|
||||||
if gid is not None:
|
if gid is not None:
|
||||||
_args["gidnumber"] = str(gid)
|
_args["gidnumber"] = gid
|
||||||
if nonposix is not None:
|
if nonposix is not None:
|
||||||
_args["nonposix"] = nonposix
|
_args["nonposix"] = nonposix
|
||||||
if external is not None:
|
if external is not None:
|
||||||
@@ -219,22 +221,22 @@ def main():
|
|||||||
# Get parameters
|
# Get parameters
|
||||||
|
|
||||||
# general
|
# general
|
||||||
ipaadmin_principal = ansible_module.params.get("ipaadmin_principal")
|
ipaadmin_principal = module_params_get(ansible_module, "ipaadmin_principal")
|
||||||
ipaadmin_password = ansible_module.params.get("ipaadmin_password")
|
ipaadmin_password = module_params_get(ansible_module, "ipaadmin_password")
|
||||||
names = ansible_module.params.get("name")
|
names = module_params_get(ansible_module, "name")
|
||||||
|
|
||||||
# present
|
# present
|
||||||
description = ansible_module.params.get("description")
|
description = module_params_get(ansible_module, "description")
|
||||||
gid = ansible_module.params.get("gid")
|
gid = module_params_get(ansible_module, "gid")
|
||||||
nonposix = ansible_module.params.get("nonposix")
|
nonposix = module_params_get(ansible_module, "nonposix")
|
||||||
external = ansible_module.params.get("external")
|
external = module_params_get(ansible_module, "external")
|
||||||
nomembers = ansible_module.params.get("nomembers")
|
nomembers = module_params_get(ansible_module, "nomembers")
|
||||||
user = ansible_module.params.get("user")
|
user = module_params_get(ansible_module, "user")
|
||||||
group = ansible_module.params.get("group")
|
group = module_params_get(ansible_module, "group")
|
||||||
service = ansible_module.params.get("service")
|
service = module_params_get(ansible_module, "service")
|
||||||
action = ansible_module.params.get("action")
|
action = module_params_get(ansible_module, "action")
|
||||||
# state
|
# state
|
||||||
state = ansible_module.params.get("state")
|
state = module_params_get(ansible_module, "state")
|
||||||
|
|
||||||
# Check parameters
|
# Check parameters
|
||||||
|
|
||||||
@@ -276,6 +278,12 @@ def main():
|
|||||||
ipaadmin_password)
|
ipaadmin_password)
|
||||||
api_connect()
|
api_connect()
|
||||||
|
|
||||||
|
has_add_member_service = api_check_param("group_add_member", "service")
|
||||||
|
if service is not None and not has_add_member_service:
|
||||||
|
ansible_module.fail_json(
|
||||||
|
msg="Managing a service as part of a group is not supported "
|
||||||
|
"by your IPA version")
|
||||||
|
|
||||||
commands = []
|
commands = []
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
@@ -325,6 +333,7 @@ def main():
|
|||||||
set(res_find.get("member_service", [])) -
|
set(res_find.get("member_service", [])) -
|
||||||
set(service or []))
|
set(service or []))
|
||||||
|
|
||||||
|
if has_add_member_service:
|
||||||
# Add members
|
# Add members
|
||||||
if len(user_add) > 0 or len(group_add) > 0 or \
|
if len(user_add) > 0 or len(group_add) > 0 or \
|
||||||
len(service_add) > 0:
|
len(service_add) > 0:
|
||||||
@@ -343,16 +352,37 @@ def main():
|
|||||||
"group": group_del,
|
"group": group_del,
|
||||||
"service": service_del,
|
"service": service_del,
|
||||||
}])
|
}])
|
||||||
|
else:
|
||||||
|
# Add members
|
||||||
|
if len(user_add) > 0 or len(group_add) > 0:
|
||||||
|
commands.append([name, "group_add_member",
|
||||||
|
{
|
||||||
|
"user": user_add,
|
||||||
|
"group": group_add,
|
||||||
|
}])
|
||||||
|
# Remove members
|
||||||
|
if len(user_del) > 0 or len(group_del) > 0:
|
||||||
|
commands.append([name, "group_remove_member",
|
||||||
|
{
|
||||||
|
"user": user_del,
|
||||||
|
"group": group_del,
|
||||||
|
}])
|
||||||
elif action == "member":
|
elif action == "member":
|
||||||
if res_find is None:
|
if res_find is None:
|
||||||
ansible_module.fail_json(msg="No group '%s'" % name)
|
ansible_module.fail_json(msg="No group '%s'" % name)
|
||||||
|
if has_add_member_service:
|
||||||
commands.append([name, "group_add_member",
|
commands.append([name, "group_add_member",
|
||||||
{
|
{
|
||||||
"user": user,
|
"user": user,
|
||||||
"group": group,
|
"group": group,
|
||||||
"service": service,
|
"service": service,
|
||||||
}])
|
}])
|
||||||
|
else:
|
||||||
|
commands.append([name, "group_add_member",
|
||||||
|
{
|
||||||
|
"user": user,
|
||||||
|
"group": group,
|
||||||
|
}])
|
||||||
|
|
||||||
elif state == "absent":
|
elif state == "absent":
|
||||||
if action == "group":
|
if action == "group":
|
||||||
@@ -376,7 +406,7 @@ def main():
|
|||||||
|
|
||||||
for name, command, args in commands:
|
for name, command, args in commands:
|
||||||
try:
|
try:
|
||||||
result = api_command(ansible_module, command, to_text(name),
|
result = api_command(ansible_module, command, name,
|
||||||
args)
|
args)
|
||||||
if "completed" in result and result["completed"] > 0:
|
if "completed" in result and result["completed"] > 0:
|
||||||
changed = True
|
changed = True
|
||||||
|
|||||||
Reference in New Issue
Block a user