|
|
@ -21,6 +21,8 @@
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
import crypt
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.univention_umc import (
|
|
|
|
from ansible.module_utils.univention_umc import (
|
|
|
|
umc_module_for_add,
|
|
|
|
umc_module_for_add,
|
|
|
@ -28,9 +30,7 @@ from ansible.module_utils.univention_umc import (
|
|
|
|
ldap_search,
|
|
|
|
ldap_search,
|
|
|
|
base_dn,
|
|
|
|
base_dn,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
import crypt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
DOCUMENTATION = '''
|
|
|
@ -40,7 +40,8 @@ version_added: "2.2"
|
|
|
|
author: "Tobias Rueetschi (@2-B)"
|
|
|
|
author: "Tobias Rueetschi (@2-B)"
|
|
|
|
short_description: Manage posix users on a univention corporate server
|
|
|
|
short_description: Manage posix users on a univention corporate server
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- "This module allows to manage posix users on a univention corporate server (UCS).
|
|
|
|
- "This module allows to manage posix users on a univention corporate
|
|
|
|
|
|
|
|
server (UCS).
|
|
|
|
It uses the python API of the UCS to create a new object or edit it."
|
|
|
|
It uses the python API of the UCS to create a new object or edit it."
|
|
|
|
requirements:
|
|
|
|
requirements:
|
|
|
|
- Python >= 2.6
|
|
|
|
- Python >= 2.6
|
|
|
@ -268,8 +269,8 @@ options:
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: ''
|
|
|
|
default: ''
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- "Define the whole position of users object inside the LDAP tree, e.g.
|
|
|
|
- "Define the whole position of users object inside the LDAP tree,
|
|
|
|
C(cn=employee,cn=users,ou=school,dc=example,dc=com)."
|
|
|
|
e.g. C(cn=employee,cn=users,ou=school,dc=example,dc=com)."
|
|
|
|
ou:
|
|
|
|
ou:
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: ''
|
|
|
|
default: ''
|
|
|
@ -449,25 +450,25 @@ def main():
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
obj = umc_module_for_edit('users/user', user_dn)
|
|
|
|
obj = umc_module_for_edit('users/user', user_dn)
|
|
|
|
|
|
|
|
|
|
|
|
if module.params['displayName'] == None:
|
|
|
|
if module.params['displayName'] is None:
|
|
|
|
module.params['displayName'] = '{} {}'.format(
|
|
|
|
module.params['displayName'] = '{} {}'.format(
|
|
|
|
module.params['firstname'],
|
|
|
|
module.params['firstname'],
|
|
|
|
module.params['lastname']
|
|
|
|
module.params['lastname']
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if module.params['unixhome'] == None:
|
|
|
|
if module.params['unixhome'] is None:
|
|
|
|
module.params['unixhome'] = '/home/{}'.format(
|
|
|
|
module.params['unixhome'] = '/home/{}'.format(
|
|
|
|
module.params['username']
|
|
|
|
module.params['username']
|
|
|
|
)
|
|
|
|
)
|
|
|
|
for k in obj.keys():
|
|
|
|
for k in obj.keys():
|
|
|
|
if (k != 'password' and
|
|
|
|
if (k != 'password' and
|
|
|
|
k != 'groups' and
|
|
|
|
k != 'groups' and
|
|
|
|
module.params.has_key(k) and
|
|
|
|
k in module.params and
|
|
|
|
module.params[k] != None):
|
|
|
|
module.params[k] is not None):
|
|
|
|
obj[k] = module.params[k]
|
|
|
|
obj[k] = module.params[k]
|
|
|
|
# handle some special values
|
|
|
|
# handle some special values
|
|
|
|
obj['e-mail'] = module.params['email']
|
|
|
|
obj['e-mail'] = module.params['email']
|
|
|
|
password = module.params['password']
|
|
|
|
password = module.params['password']
|
|
|
|
if obj['password'] == None:
|
|
|
|
if obj['password'] is None:
|
|
|
|
obj['password'] = password
|
|
|
|
obj['password'] = password
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
old_password = obj['password'].split('}', 2)[1]
|
|
|
|
old_password = obj['password'].split('}', 2)[1]
|
|
|
@ -488,12 +489,17 @@ def main():
|
|
|
|
obj.modify()
|
|
|
|
obj.modify()
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
module.fail_json(
|
|
|
|
module.fail_json(
|
|
|
|
msg="Creating/editing user {} in {} failed".format(username, container)
|
|
|
|
msg="Creating/editing user {} in {} failed".format(
|
|
|
|
|
|
|
|
username,
|
|
|
|
|
|
|
|
container
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
groups = module.params['groups']
|
|
|
|
groups = module.params['groups']
|
|
|
|
if groups:
|
|
|
|
if groups:
|
|
|
|
filter = '(&(objectClass=posixGroup)(|(cn={})))'.format(')(cn='.join(groups))
|
|
|
|
filter = '(&(objectClass=posixGroup)(|(cn={})))'.format(
|
|
|
|
|
|
|
|
')(cn='.join(groups)
|
|
|
|
|
|
|
|
)
|
|
|
|
group_dns = list(ldap_search(filter, attr=['dn']))
|
|
|
|
group_dns = list(ldap_search(filter, attr=['dn']))
|
|
|
|
for dn in group_dns:
|
|
|
|
for dn in group_dns:
|
|
|
|
grp = umc_module_for_edit('groups/group', dn[0])
|
|
|
|
grp = umc_module_for_edit('groups/group', dn[0])
|
|
|
|