1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-21 19:29:05 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -97,54 +97,45 @@ from ansible_collections.community.general.plugins.module_utils.univention_umc i
def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(required=True,
type='str'),
description=dict(type='str'),
position=dict(default='',
type='str'),
ou=dict(default='',
type='str'),
subpath=dict(default='cn=groups',
type='str'),
state=dict(default='present',
choices=['present', 'absent'],
type='str')
name=dict(required=True, type="str"),
description=dict(type="str"),
position=dict(default="", type="str"),
ou=dict(default="", type="str"),
subpath=dict(default="cn=groups", type="str"),
state=dict(default="present", choices=["present", "absent"], type="str"),
),
supports_check_mode=True
supports_check_mode=True,
)
name = module.params['name']
description = module.params['description']
position = module.params['position']
ou = module.params['ou']
subpath = module.params['subpath']
state = module.params['state']
name = module.params["name"]
description = module.params["description"]
position = module.params["position"]
ou = module.params["ou"]
subpath = module.params["subpath"]
state = module.params["state"]
changed = False
diff = None
groups = list(ldap_search(
f'(&(objectClass=posixGroup)(cn={name}))',
attr=['cn']
))
if position != '':
groups = list(ldap_search(f"(&(objectClass=posixGroup)(cn={name}))", attr=["cn"]))
if position != "":
container = position
else:
if ou != '':
ou = f'ou={ou},'
if subpath != '':
subpath = f'{subpath},'
container = f'{subpath}{ou}{base_dn()}'
group_dn = f'cn={name},{container}'
if ou != "":
ou = f"ou={ou},"
if subpath != "":
subpath = f"{subpath},"
container = f"{subpath}{ou}{base_dn()}"
group_dn = f"cn={name},{container}"
exists = bool(len(groups))
if state == 'present':
if state == "present":
try:
if not exists:
grp = umc_module_for_add('groups/group', container)
grp = umc_module_for_add("groups/group", container)
else:
grp = umc_module_for_edit('groups/group', group_dn)
grp['name'] = name
grp['description'] = description
grp = umc_module_for_edit("groups/group", group_dn)
grp["name"] = name
grp["description"] = description
diff = grp.diff()
changed = grp.diff() != []
if not module.check_mode:
@ -153,28 +144,19 @@ def main():
else:
grp.modify()
except Exception:
module.fail_json(
msg=f"Creating/editing group {name} in {container} failed"
)
module.fail_json(msg=f"Creating/editing group {name} in {container} failed")
if state == 'absent' and exists:
if state == "absent" and exists:
try:
grp = umc_module_for_edit('groups/group', group_dn)
grp = umc_module_for_edit("groups/group", group_dn)
if not module.check_mode:
grp.remove()
changed = True
except Exception:
module.fail_json(
msg=f"Removing group {name} failed"
)
module.fail_json(msg=f"Removing group {name} failed")
module.exit_json(
changed=changed,
name=name,
diff=diff,
container=container
)
module.exit_json(changed=changed, name=name, diff=diff, container=container)
if __name__ == '__main__':
if __name__ == "__main__":
main()