2020-03-09 10:11:07 +01:00
|
|
|
#!/usr/bin/python
|
2021-08-08 10:40:22 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2022-08-05 12:28:29 +02:00
|
|
|
# Copyright (c) 2016, Adfinis SyGroup AG
|
2020-03-09 10:11:07 +01:00
|
|
|
# Tobias Rueetschi <tobias.ruetschi@adfinis-sygroup.ch>
|
2022-08-05 12:28:29 +02:00
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
2020-03-24 09:27:28 +01:00
|
|
|
DOCUMENTATION = r'''
|
2020-03-09 10:11:07 +01:00
|
|
|
---
|
|
|
|
module: udm_user
|
|
|
|
author:
|
2023-02-24 09:23:28 +01:00
|
|
|
- Tobias Rüetschi (@keachi)
|
2020-03-09 10:11:07 +01:00
|
|
|
short_description: Manage posix users on a univention corporate server
|
|
|
|
description:
|
|
|
|
- "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."
|
2024-06-13 22:01:30 +02:00
|
|
|
notes:
|
|
|
|
- This module does B(not) work with Python 3.13 or newer. It uses the deprecated L(crypt Python module,
|
|
|
|
https://docs.python.org/3.12/library/crypt.html) from the Python standard library, which was removed
|
|
|
|
from Python 3.13.
|
|
|
|
requirements:
|
|
|
|
- Python 3.12 or earlier
|
2023-02-24 09:23:28 +01:00
|
|
|
extends_documentation_fragment:
|
|
|
|
- community.general.attributes
|
|
|
|
attributes:
|
|
|
|
check_mode:
|
|
|
|
support: full
|
|
|
|
diff_mode:
|
|
|
|
support: partial
|
2020-03-09 10:11:07 +01:00
|
|
|
options:
|
|
|
|
state:
|
|
|
|
default: "present"
|
|
|
|
choices: [ present, absent ]
|
|
|
|
description:
|
|
|
|
- Whether the user is present or not.
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
username:
|
|
|
|
required: true
|
|
|
|
description:
|
|
|
|
- User name
|
|
|
|
aliases: ['name']
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
firstname:
|
|
|
|
description:
|
2023-06-18 19:48:01 +02:00
|
|
|
- First name. Required if O(state=present).
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
lastname:
|
|
|
|
description:
|
2023-06-18 19:48:01 +02:00
|
|
|
- Last name. Required if O(state=present).
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
password:
|
|
|
|
description:
|
2023-06-18 19:48:01 +02:00
|
|
|
- Password. Required if O(state=present).
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
birthday:
|
|
|
|
description:
|
|
|
|
- Birthday
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
city:
|
|
|
|
description:
|
|
|
|
- City of users business address.
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
country:
|
|
|
|
description:
|
|
|
|
- Country of users business address.
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
department_number:
|
|
|
|
description:
|
|
|
|
- Department number of users business address.
|
|
|
|
aliases: [ departmentNumber ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Description (not gecos)
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
display_name:
|
|
|
|
description:
|
|
|
|
- Display name (not gecos)
|
|
|
|
aliases: [ displayName ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
email:
|
2020-12-01 21:28:40 +01:00
|
|
|
default: ['']
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- A list of e-mail addresses.
|
2020-12-01 21:28:40 +01:00
|
|
|
type: list
|
2022-11-23 18:43:58 +01:00
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
employee_number:
|
|
|
|
description:
|
|
|
|
- Employee number
|
|
|
|
aliases: [ employeeNumber ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
employee_type:
|
|
|
|
description:
|
|
|
|
- Employee type
|
|
|
|
aliases: [ employeeType ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
gecos:
|
|
|
|
description:
|
|
|
|
- GECOS
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
groups:
|
|
|
|
default: []
|
|
|
|
description:
|
|
|
|
- "POSIX groups, the LDAP DNs of the groups will be found with the
|
|
|
|
LDAP filter for each group as $GROUP:
|
2023-06-18 19:48:01 +02:00
|
|
|
V((&(objectClass=posixGroup\\)(cn=$GROUP\\)\\))."
|
2020-12-01 21:28:40 +01:00
|
|
|
type: list
|
2022-11-23 18:43:58 +01:00
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
home_share:
|
|
|
|
description:
|
|
|
|
- "Home NFS share. Must be a LDAP DN, e.g.
|
2023-06-18 19:48:01 +02:00
|
|
|
V(cn=home,cn=shares,ou=school,dc=example,dc=com)."
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases: [ homeShare ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
home_share_path:
|
|
|
|
description:
|
|
|
|
- Path to home NFS share, inside the homeShare.
|
|
|
|
aliases: [ homeSharePath ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
home_telephone_number:
|
|
|
|
default: []
|
|
|
|
description:
|
|
|
|
- List of private telephone numbers.
|
|
|
|
aliases: [ homeTelephoneNumber ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: list
|
2022-11-23 18:43:58 +01:00
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
homedrive:
|
|
|
|
description:
|
2023-06-18 19:48:01 +02:00
|
|
|
- Windows home drive, for example V("H:").
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
mail_alternative_address:
|
|
|
|
default: []
|
|
|
|
description:
|
|
|
|
- List of alternative e-mail addresses.
|
|
|
|
aliases: [ mailAlternativeAddress ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: list
|
2022-11-23 18:43:58 +01:00
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
mail_home_server:
|
|
|
|
description:
|
|
|
|
- FQDN of mail server
|
|
|
|
aliases: [ mailHomeServer ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
mail_primary_address:
|
|
|
|
description:
|
|
|
|
- Primary e-mail address
|
|
|
|
aliases: [ mailPrimaryAddress ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
mobile_telephone_number:
|
|
|
|
default: []
|
|
|
|
description:
|
|
|
|
- Mobile phone number
|
|
|
|
aliases: [ mobileTelephoneNumber ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: list
|
2022-11-23 18:43:58 +01:00
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
organisation:
|
|
|
|
description:
|
|
|
|
- Organisation
|
|
|
|
aliases: [ organization ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
|
|
|
overridePWHistory:
|
2020-03-09 10:11:07 +01:00
|
|
|
type: bool
|
2022-08-24 20:16:25 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Override password history
|
2020-12-01 21:28:40 +01:00
|
|
|
aliases: [ override_pw_history ]
|
|
|
|
overridePWLength:
|
2020-03-09 10:11:07 +01:00
|
|
|
type: bool
|
2022-08-24 20:16:25 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Override password check
|
2020-12-01 21:28:40 +01:00
|
|
|
aliases: [ override_pw_length ]
|
2020-03-09 10:11:07 +01:00
|
|
|
pager_telephonenumber:
|
|
|
|
default: []
|
|
|
|
description:
|
|
|
|
- List of pager telephone numbers.
|
|
|
|
aliases: [ pagerTelephonenumber ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: list
|
2022-11-23 18:43:58 +01:00
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
phone:
|
|
|
|
description:
|
|
|
|
- List of telephone numbers.
|
2020-12-01 21:28:40 +01:00
|
|
|
type: list
|
2022-11-23 18:43:58 +01:00
|
|
|
elements: str
|
2022-11-01 19:25:51 +01:00
|
|
|
default: []
|
2020-03-09 10:11:07 +01:00
|
|
|
postcode:
|
|
|
|
description:
|
|
|
|
- Postal code of users business address.
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
primary_group:
|
|
|
|
description:
|
|
|
|
- Primary group. This must be the group LDAP DN.
|
2023-06-18 19:48:01 +02:00
|
|
|
- If not specified, it defaults to V(cn=Domain Users,cn=groups,$LDAP_BASE_DN).
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases: [ primaryGroup ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
profilepath:
|
|
|
|
description:
|
|
|
|
- Windows profile directory
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
pwd_change_next_login:
|
|
|
|
choices: [ '0', '1' ]
|
|
|
|
description:
|
|
|
|
- Change password on next login.
|
|
|
|
aliases: [ pwdChangeNextLogin ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
room_number:
|
|
|
|
description:
|
|
|
|
- Room number of users business address.
|
|
|
|
aliases: [ roomNumber ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
samba_privileges:
|
|
|
|
description:
|
|
|
|
- "Samba privilege, like allow printer administration, do domain
|
|
|
|
join."
|
|
|
|
aliases: [ sambaPrivileges ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: list
|
2022-11-23 18:43:58 +01:00
|
|
|
elements: str
|
2022-11-01 19:25:51 +01:00
|
|
|
default: []
|
2020-03-09 10:11:07 +01:00
|
|
|
samba_user_workstations:
|
|
|
|
description:
|
|
|
|
- Allow the authentication only on this Microsoft Windows host.
|
|
|
|
aliases: [ sambaUserWorkstations ]
|
2020-12-01 21:28:40 +01:00
|
|
|
type: list
|
2022-11-23 18:43:58 +01:00
|
|
|
elements: str
|
2022-11-01 19:25:51 +01:00
|
|
|
default: []
|
2020-03-09 10:11:07 +01:00
|
|
|
sambahome:
|
|
|
|
description:
|
2023-06-18 19:48:01 +02:00
|
|
|
- Windows home path, for example V('\\\\$FQDN\\$USERNAME').
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
scriptpath:
|
|
|
|
description:
|
|
|
|
- Windows logon script.
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
secretary:
|
|
|
|
default: []
|
|
|
|
description:
|
|
|
|
- A list of superiors as LDAP DNs.
|
2020-12-01 21:28:40 +01:00
|
|
|
type: list
|
2022-11-23 18:43:58 +01:00
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
serviceprovider:
|
2020-12-01 21:28:40 +01:00
|
|
|
default: ['']
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Enable user for the following service providers.
|
2020-12-01 21:28:40 +01:00
|
|
|
type: list
|
2022-11-23 18:43:58 +01:00
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
shell:
|
|
|
|
default: '/bin/bash'
|
|
|
|
description:
|
|
|
|
- Login shell
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
street:
|
|
|
|
description:
|
|
|
|
- Street of users business address.
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
title:
|
|
|
|
description:
|
2023-06-18 19:48:01 +02:00
|
|
|
- Title, for example V(Prof.).
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
unixhome:
|
|
|
|
description:
|
|
|
|
- Unix home directory
|
2020-12-01 21:28:40 +01:00
|
|
|
- If not specified, it defaults to C(/home/$USERNAME).
|
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
userexpiry:
|
|
|
|
description:
|
2023-06-18 19:48:01 +02:00
|
|
|
- Account expiry date, for example V(1999-12-31).
|
2020-12-01 21:28:40 +01:00
|
|
|
- If not specified, it defaults to the current day plus one year.
|
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
position:
|
|
|
|
default: ''
|
|
|
|
description:
|
|
|
|
- "Define the whole position of users object inside the LDAP tree,
|
2023-06-18 19:48:01 +02:00
|
|
|
for example V(cn=employee,cn=users,ou=school,dc=example,dc=com)."
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
update_password:
|
|
|
|
default: always
|
2020-11-27 21:16:47 +01:00
|
|
|
choices: [ always, on_create ]
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
2023-06-18 19:48:01 +02:00
|
|
|
- "V(always) will update passwords if they differ.
|
|
|
|
V(on_create) will only set the password for newly created users."
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
ou:
|
|
|
|
default: ''
|
|
|
|
description:
|
2023-06-18 19:48:01 +02:00
|
|
|
- "Organizational Unit inside the LDAP Base DN, for example V(school) for
|
2020-03-09 10:11:07 +01:00
|
|
|
LDAP OU C(ou=school,dc=example,dc=com)."
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
subpath:
|
|
|
|
default: 'cn=users'
|
|
|
|
description:
|
2023-06-18 19:48:01 +02:00
|
|
|
- "LDAP subpath inside the organizational unit, for example
|
|
|
|
V(cn=teachers,cn=users) for LDAP container
|
2020-03-09 10:11:07 +01:00
|
|
|
C(cn=teachers,cn=users,dc=example,dc=com)."
|
2020-12-01 21:28:40 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
2020-05-15 12:12:41 +02:00
|
|
|
- name: Create a user on a UCS
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.udm_user:
|
2020-03-09 10:11:07 +01:00
|
|
|
name: FooBar
|
|
|
|
password: secure_password
|
|
|
|
firstname: Foo
|
|
|
|
lastname: Bar
|
|
|
|
|
2023-06-18 19:48:01 +02:00
|
|
|
- name: Create a user with the DN uid=foo,cn=teachers,cn=users,ou=school,dc=school,dc=example,dc=com
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.udm_user:
|
2020-03-09 10:11:07 +01:00
|
|
|
name: foo
|
|
|
|
password: secure_password
|
|
|
|
firstname: Foo
|
|
|
|
lastname: Bar
|
|
|
|
ou: school
|
|
|
|
subpath: 'cn=teachers,cn=users'
|
2020-05-15 12:12:41 +02:00
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
# or define the position
|
2023-06-18 19:48:01 +02:00
|
|
|
- name: Create a user with the DN uid=foo,cn=teachers,cn=users,ou=school,dc=school,dc=example,dc=com
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.udm_user:
|
2020-03-09 10:11:07 +01:00
|
|
|
name: foo
|
|
|
|
password: secure_password
|
|
|
|
firstname: Foo
|
|
|
|
lastname: Bar
|
|
|
|
position: 'cn=teachers,cn=users,ou=school,dc=school,dc=example,dc=com'
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
RETURN = '''# '''
|
|
|
|
|
|
|
|
from datetime import date, timedelta
|
2024-06-13 22:01:30 +02:00
|
|
|
import traceback
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2024-06-13 22:01:30 +02:00
|
|
|
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
2020-03-09 10:11:07 +01:00
|
|
|
from ansible_collections.community.general.plugins.module_utils.univention_umc import (
|
|
|
|
umc_module_for_add,
|
|
|
|
umc_module_for_edit,
|
|
|
|
ldap_search,
|
|
|
|
base_dn,
|
|
|
|
)
|
|
|
|
|
2024-06-13 22:01:30 +02:00
|
|
|
try:
|
|
|
|
import crypt
|
|
|
|
except ImportError:
|
|
|
|
HAS_CRYPT = False
|
|
|
|
CRYPT_IMPORT_ERROR = traceback.format_exc()
|
|
|
|
else:
|
|
|
|
HAS_CRYPT = True
|
|
|
|
CRYPT_IMPORT_ERROR = None
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
def main():
|
|
|
|
expiry = date.strftime(date.today() + timedelta(days=365), "%Y-%m-%d")
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
2020-12-01 21:28:40 +01:00
|
|
|
birthday=dict(type='str'),
|
|
|
|
city=dict(type='str'),
|
|
|
|
country=dict(type='str'),
|
|
|
|
department_number=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['departmentNumber']),
|
2020-12-01 21:28:40 +01:00
|
|
|
description=dict(type='str'),
|
|
|
|
display_name=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['displayName']),
|
|
|
|
email=dict(default=[''],
|
2022-11-23 18:43:58 +01:00
|
|
|
type='list',
|
|
|
|
elements='str'),
|
2020-12-01 21:28:40 +01:00
|
|
|
employee_number=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['employeeNumber']),
|
2020-12-01 21:28:40 +01:00
|
|
|
employee_type=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['employeeType']),
|
2020-12-01 21:28:40 +01:00
|
|
|
firstname=dict(type='str'),
|
|
|
|
gecos=dict(type='str'),
|
2020-03-09 10:11:07 +01:00
|
|
|
groups=dict(default=[],
|
2022-11-23 18:43:58 +01:00
|
|
|
type='list',
|
|
|
|
elements='str'),
|
2020-12-01 21:28:40 +01:00
|
|
|
home_share=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['homeShare']),
|
2020-12-01 21:28:40 +01:00
|
|
|
home_share_path=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['homeSharePath']),
|
|
|
|
home_telephone_number=dict(default=[],
|
|
|
|
type='list',
|
2022-11-23 18:43:58 +01:00
|
|
|
elements='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['homeTelephoneNumber']),
|
2020-12-01 21:28:40 +01:00
|
|
|
homedrive=dict(type='str'),
|
|
|
|
lastname=dict(type='str'),
|
2020-03-09 10:11:07 +01:00
|
|
|
mail_alternative_address=dict(default=[],
|
|
|
|
type='list',
|
2022-11-23 18:43:58 +01:00
|
|
|
elements='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['mailAlternativeAddress']),
|
2020-12-01 21:28:40 +01:00
|
|
|
mail_home_server=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['mailHomeServer']),
|
2020-12-01 21:28:40 +01:00
|
|
|
mail_primary_address=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['mailPrimaryAddress']),
|
|
|
|
mobile_telephone_number=dict(default=[],
|
|
|
|
type='list',
|
2022-11-23 18:43:58 +01:00
|
|
|
elements='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['mobileTelephoneNumber']),
|
2020-12-01 21:28:40 +01:00
|
|
|
organisation=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['organization']),
|
|
|
|
overridePWHistory=dict(default=False,
|
|
|
|
type='bool',
|
|
|
|
aliases=['override_pw_history']),
|
|
|
|
overridePWLength=dict(default=False,
|
|
|
|
type='bool',
|
|
|
|
aliases=['override_pw_length']),
|
|
|
|
pager_telephonenumber=dict(default=[],
|
|
|
|
type='list',
|
2022-11-23 18:43:58 +01:00
|
|
|
elements='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['pagerTelephonenumber']),
|
2020-12-01 21:28:40 +01:00
|
|
|
password=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
no_log=True),
|
|
|
|
phone=dict(default=[],
|
2022-11-23 18:43:58 +01:00
|
|
|
type='list',
|
|
|
|
elements='str'),
|
2020-12-01 21:28:40 +01:00
|
|
|
postcode=dict(type='str'),
|
|
|
|
primary_group=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['primaryGroup']),
|
2020-12-01 21:28:40 +01:00
|
|
|
profilepath=dict(type='str'),
|
|
|
|
pwd_change_next_login=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
choices=['0', '1'],
|
|
|
|
aliases=['pwdChangeNextLogin']),
|
2020-12-01 21:28:40 +01:00
|
|
|
room_number=dict(type='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['roomNumber']),
|
|
|
|
samba_privileges=dict(default=[],
|
|
|
|
type='list',
|
2022-11-23 18:43:58 +01:00
|
|
|
elements='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['sambaPrivileges']),
|
|
|
|
samba_user_workstations=dict(default=[],
|
|
|
|
type='list',
|
2022-11-23 18:43:58 +01:00
|
|
|
elements='str',
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases=['sambaUserWorkstations']),
|
2020-12-01 21:28:40 +01:00
|
|
|
sambahome=dict(type='str'),
|
|
|
|
scriptpath=dict(type='str'),
|
2020-03-09 10:11:07 +01:00
|
|
|
secretary=dict(default=[],
|
2022-11-23 18:43:58 +01:00
|
|
|
type='list',
|
|
|
|
elements='str'),
|
2020-03-09 10:11:07 +01:00
|
|
|
serviceprovider=dict(default=[''],
|
2022-11-23 18:43:58 +01:00
|
|
|
type='list',
|
|
|
|
elements='str'),
|
2020-03-09 10:11:07 +01:00
|
|
|
shell=dict(default='/bin/bash',
|
|
|
|
type='str'),
|
2020-12-01 21:28:40 +01:00
|
|
|
street=dict(type='str'),
|
|
|
|
title=dict(type='str'),
|
|
|
|
unixhome=dict(type='str'),
|
|
|
|
userexpiry=dict(type='str'),
|
2020-03-09 10:11:07 +01:00
|
|
|
username=dict(required=True,
|
|
|
|
aliases=['name'],
|
|
|
|
type='str'),
|
|
|
|
position=dict(default='',
|
|
|
|
type='str'),
|
|
|
|
update_password=dict(default='always',
|
|
|
|
choices=['always', 'on_create'],
|
|
|
|
type='str'),
|
|
|
|
ou=dict(default='',
|
|
|
|
type='str'),
|
|
|
|
subpath=dict(default='cn=users',
|
|
|
|
type='str'),
|
|
|
|
state=dict(default='present',
|
|
|
|
choices=['present', 'absent'],
|
|
|
|
type='str')
|
|
|
|
),
|
|
|
|
supports_check_mode=True,
|
|
|
|
required_if=([
|
|
|
|
('state', 'present', ['firstname', 'lastname', 'password'])
|
|
|
|
])
|
|
|
|
)
|
2024-06-13 22:01:30 +02:00
|
|
|
|
|
|
|
if not HAS_CRYPT:
|
|
|
|
module.fail_json(
|
|
|
|
msg=missing_required_lib('crypt (part of Python 3.13 standard library)'),
|
|
|
|
exception=CRYPT_IMPORT_ERROR,
|
|
|
|
)
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
username = module.params['username']
|
|
|
|
position = module.params['position']
|
|
|
|
ou = module.params['ou']
|
|
|
|
subpath = module.params['subpath']
|
|
|
|
state = module.params['state']
|
|
|
|
changed = False
|
|
|
|
diff = None
|
|
|
|
|
|
|
|
users = list(ldap_search(
|
|
|
|
'(&(objectClass=posixAccount)(uid={0}))'.format(username),
|
|
|
|
attr=['uid']
|
|
|
|
))
|
|
|
|
if position != '':
|
|
|
|
container = position
|
|
|
|
else:
|
|
|
|
if ou != '':
|
|
|
|
ou = 'ou={0},'.format(ou)
|
|
|
|
if subpath != '':
|
|
|
|
subpath = '{0},'.format(subpath)
|
|
|
|
container = '{0}{1}{2}'.format(subpath, ou, base_dn())
|
|
|
|
user_dn = 'uid={0},{1}'.format(username, container)
|
|
|
|
|
|
|
|
exists = bool(len(users))
|
|
|
|
|
|
|
|
if state == 'present':
|
|
|
|
try:
|
|
|
|
if not exists:
|
|
|
|
obj = umc_module_for_add('users/user', container)
|
|
|
|
else:
|
|
|
|
obj = umc_module_for_edit('users/user', user_dn)
|
|
|
|
|
|
|
|
if module.params['displayName'] is None:
|
|
|
|
module.params['displayName'] = '{0} {1}'.format(
|
|
|
|
module.params['firstname'],
|
|
|
|
module.params['lastname']
|
|
|
|
)
|
|
|
|
if module.params['unixhome'] is None:
|
|
|
|
module.params['unixhome'] = '/home/{0}'.format(
|
|
|
|
module.params['username']
|
|
|
|
)
|
|
|
|
for k in obj.keys():
|
|
|
|
if (k != 'password' and
|
|
|
|
k != 'groups' and
|
|
|
|
k != 'overridePWHistory' and
|
|
|
|
k in module.params and
|
|
|
|
module.params[k] is not None):
|
|
|
|
obj[k] = module.params[k]
|
|
|
|
# handle some special values
|
|
|
|
obj['e-mail'] = module.params['email']
|
2020-12-01 21:28:40 +01:00
|
|
|
if 'userexpiry' in obj and obj.get('userexpiry') is None:
|
|
|
|
obj['userexpiry'] = expiry
|
2020-03-09 10:11:07 +01:00
|
|
|
password = module.params['password']
|
|
|
|
if obj['password'] is None:
|
|
|
|
obj['password'] = password
|
|
|
|
if module.params['update_password'] == 'always':
|
|
|
|
old_password = obj['password'].split('}', 2)[1]
|
|
|
|
if crypt.crypt(password, old_password) != old_password:
|
|
|
|
obj['overridePWHistory'] = module.params['overridePWHistory']
|
|
|
|
obj['overridePWLength'] = module.params['overridePWLength']
|
|
|
|
obj['password'] = password
|
|
|
|
|
|
|
|
diff = obj.diff()
|
|
|
|
if exists:
|
|
|
|
for k in obj.keys():
|
|
|
|
if obj.hasChanged(k):
|
|
|
|
changed = True
|
|
|
|
else:
|
|
|
|
changed = True
|
|
|
|
if not module.check_mode:
|
|
|
|
if not exists:
|
|
|
|
obj.create()
|
|
|
|
elif changed:
|
|
|
|
obj.modify()
|
|
|
|
except Exception:
|
|
|
|
module.fail_json(
|
|
|
|
msg="Creating/editing user {0} in {1} failed".format(
|
|
|
|
username,
|
|
|
|
container
|
|
|
|
)
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
groups = module.params['groups']
|
|
|
|
if groups:
|
|
|
|
filter = '(&(objectClass=posixGroup)(|(cn={0})))'.format(
|
|
|
|
')(cn='.join(groups)
|
|
|
|
)
|
|
|
|
group_dns = list(ldap_search(filter, attr=['dn']))
|
|
|
|
for dn in group_dns:
|
|
|
|
grp = umc_module_for_edit('groups/group', dn[0])
|
|
|
|
if user_dn not in grp['users']:
|
|
|
|
grp['users'].append(user_dn)
|
|
|
|
if not module.check_mode:
|
|
|
|
grp.modify()
|
|
|
|
changed = True
|
|
|
|
except Exception:
|
|
|
|
module.fail_json(
|
|
|
|
msg="Adding groups to user {0} failed".format(username)
|
|
|
|
)
|
|
|
|
|
|
|
|
if state == 'absent' and exists:
|
|
|
|
try:
|
|
|
|
obj = umc_module_for_edit('users/user', user_dn)
|
|
|
|
if not module.check_mode:
|
|
|
|
obj.remove()
|
|
|
|
changed = True
|
|
|
|
except Exception:
|
|
|
|
module.fail_json(
|
|
|
|
msg="Removing user {0} failed".format(username)
|
|
|
|
)
|
|
|
|
|
|
|
|
module.exit_json(
|
|
|
|
changed=changed,
|
|
|
|
username=username,
|
|
|
|
diff=diff,
|
|
|
|
container=container
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|