| 1 |
# Copyright: (c) 2023, Ansible Project |
| 2 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 3 |
|
| 4 |
DOCUMENTATION: |
| 5 |
module: user |
| 6 |
short_description: Manage Active Directory users |
| 7 |
description: |
| 8 |
- Manages Active Directory users and their attributes. |
| 9 |
options: |
| 10 |
account_locked: |
| 11 |
description: |
| 12 |
- C(no) will unlock the user account if locked. |
| 13 |
- Note that there is not a way to lock an account as an administrator. |
| 14 |
- Accounts are locked due to user actions; as an admin, you may only |
| 15 |
unlock a locked account. |
| 16 |
- If you wish to administratively disable an account, set I(enabled) to |
| 17 |
C(no). |
| 18 |
choices: |
| 19 |
- false |
| 20 |
type: bool |
| 21 |
city: |
| 22 |
description: |
| 23 |
- Configures the user's city. |
| 24 |
- This is the value set on the C(l) LDAP attribute. |
| 25 |
type: str |
| 26 |
company: |
| 27 |
description: |
| 28 |
- Configures the user's company name. |
| 29 |
- This is the value set on the C(company) LDAP attribute. |
| 30 |
type: str |
| 31 |
country: |
| 32 |
description: |
| 33 |
- Configures the user's country code. |
| 34 |
- Note that this is a two-character ISO 3166 code. |
| 35 |
- This is the value set on the C(c) LDAP attribute. |
| 36 |
type: str |
| 37 |
delegates: |
| 38 |
description: |
| 39 |
- The principal objects that the current AD object can trust for |
| 40 |
delegation to either add, remove or set. |
| 41 |
- Each subkey value is a list of values in the form of a |
| 42 |
C(distinguishedName), C(objectGUID), C(objectSid), C(sAMAccountName), |
| 43 |
or C(userPrincipalName) string or a dictionary with the I(name) and |
| 44 |
optional I(server) key. |
| 45 |
- This is the value set on the |
| 46 |
C(msDS-AllowedToActOnBehalfOfOtherIdentity) LDAP attribute. |
| 47 |
- This is a highly sensitive attribute as it allows the principals |
| 48 |
specified to impersonate any account when authenticating with the AD |
| 49 |
computer object being managed. |
| 50 |
- To clear all principals, use I(set) with an empty list. |
| 51 |
- See |
| 52 |
R(DN Lookup Attributes,ansible_collections.microsoft.ad.docsite.guide_attributes.dn_lookup_attributes) |
| 53 |
for more information on how DN lookups work. |
| 54 |
- See |
| 55 |
R(Setting list option values,ansible_collections.microsoft.ad.docsite.guide_list_values) |
| 56 |
for more information on how to add/remove/set list options. |
| 57 |
aliases: |
| 58 |
- principals_allowed_to_delegate |
| 59 |
type: dict |
| 60 |
suboptions: |
| 61 |
add: |
| 62 |
description: |
| 63 |
- Adds the principals specified as principals allowed to delegate |
| 64 |
to. |
| 65 |
- Any existing principals not specified by I(add) will be untouched |
| 66 |
unless specified by I(remove) or not in I(set). |
| 67 |
type: list |
| 68 |
elements: raw |
| 69 |
lookup_failure_action: |
| 70 |
description: |
| 71 |
- Control the action to take when the lookup fails to find the DN. |
| 72 |
- C(fail) will cause the task to fail. |
| 73 |
- C(ignore) will ignore the value and continue. |
| 74 |
- C(warn) will ignore the value and display a warning. |
| 75 |
choices: ['fail', 'ignore', 'warn'] |
| 76 |
default: fail |
| 77 |
type: str |
| 78 |
remove: |
| 79 |
description: |
| 80 |
- Removes the principals specified as principals allowed to delegate |
| 81 |
to. |
| 82 |
- Any existing principals not specified by I(remove) will be |
| 83 |
untouched unless I(set) is defined. |
| 84 |
type: list |
| 85 |
elements: raw |
| 86 |
set: |
| 87 |
description: |
| 88 |
- Sets the principals specified as principals allowed to delegate |
| 89 |
to. |
| 90 |
- This will remove any existing principals if not specified in this |
| 91 |
list. |
| 92 |
- Specify an empty list to remove all principals allowed to |
| 93 |
delegate. |
| 94 |
type: list |
| 95 |
elements: raw |
| 96 |
email: |
| 97 |
description: |
| 98 |
- Configures the user's email address. |
| 99 |
- This is a record in AD and does not do anything to configure any email |
| 100 |
servers or systems. |
| 101 |
- This is the value set on the C(mail) LDAP attribute. |
| 102 |
type: str |
| 103 |
enabled: |
| 104 |
description: |
| 105 |
- C(yes) will enable the user account. |
| 106 |
- C(no) will disable the account. |
| 107 |
- The default when creating a new is C(yes) if I(password) is specified. |
| 108 |
If no I(password) is specified then the user will not be enabled. |
| 109 |
type: bool |
| 110 |
firstname: |
| 111 |
description: |
| 112 |
- Configures the user's first name (given name). |
| 113 |
- This is the value set on the C(givenName) LDAP attribute. |
| 114 |
type: str |
| 115 |
groups: |
| 116 |
description: |
| 117 |
- Specifies the group membership the user is added, removed, or set to. |
| 118 |
- To clear all group memberships, use I(set) with an empty list. |
| 119 |
- Note that users cannot be removed from their principal group (for |
| 120 |
example, "Domain Users"). Attempting to do so will display a warning. |
| 121 |
- Adding and removing a user from a group is done on the group AD |
| 122 |
object. If the group is an object in a different domain, then it may |
| 123 |
require explicit I(server) and I(domain_credentials) for it to work. |
| 124 |
- Each subkey is set to a list of groups objects to add, remove or |
| 125 |
set as the membership of this AD user respectively. A group can be in |
| 126 |
the form of a C(distinguishedName), C(objectGUID), C(objectSid), or |
| 127 |
C(sAMAccountName). |
| 128 |
- Each subkey value is a list of group objects in the form of a |
| 129 |
C(distinguishedName), C(objectGUID), C(objectSid), C(sAMAccountName), |
| 130 |
or C(userPrincipalName) string or a dictionary with the I(name) and |
| 131 |
optional I(server) key. |
| 132 |
- See |
| 133 |
R(DN Lookup Attributes,ansible_collections.microsoft.ad.docsite.guide_attributes.dn_lookup_attributes) |
| 134 |
for more information on how DN lookups work. |
| 135 |
- See |
| 136 |
R(Setting list option values,ansible_collections.microsoft.ad.docsite.guide_list_values) |
| 137 |
for more information on how to add/remove/set list options. |
| 138 |
type: dict |
| 139 |
suboptions: |
| 140 |
add: |
| 141 |
description: |
| 142 |
- The groups to add the user to. |
| 143 |
type: list |
| 144 |
elements: raw |
| 145 |
remove: |
| 146 |
description: |
| 147 |
- The groups to remove the user from. |
| 148 |
type: list |
| 149 |
elements: raw |
| 150 |
set: |
| 151 |
description: |
| 152 |
- The only groups the user is a member of. |
| 153 |
- This will clear out any existing groups if not in the specified |
| 154 |
list. |
| 155 |
- Set to an empty list to clear all group membership of the user. |
| 156 |
type: list |
| 157 |
elements: raw |
| 158 |
lookup_failure_action: |
| 159 |
description: |
| 160 |
- Controls what happens when a group specified by C(groups) is an |
| 161 |
invalid group name. |
| 162 |
- C(fail) is the default and will return an error if any groups do not |
| 163 |
exist. |
| 164 |
- C(ignore) will ignore any groups that do not exist. |
| 165 |
- C(warn) will display a warning for any groups that do not exist |
| 166 |
but will continue without failing. |
| 167 |
aliases: |
| 168 |
- missing_behaviour |
| 169 |
choices: |
| 170 |
- fail |
| 171 |
- ignore |
| 172 |
- warn |
| 173 |
default: fail |
| 174 |
type: str |
| 175 |
permissions_failure_action: |
| 176 |
description: |
| 177 |
- Controls what happens when a group specified by C(groups) is not |
| 178 |
able to be modified by the user specified by C(domain_username) |
| 179 |
- C(fail) is the default and will return an erro if any groups |
| 180 |
membership is not modifiable by the user. |
| 181 |
- C(ignore) will ignore any groups that cannot be modified. |
| 182 |
- C(warn) will display a warning for any groups that cannot be |
| 183 |
modified but will continue without failing. |
| 184 |
choices: |
| 185 |
- fail |
| 186 |
- ignore |
| 187 |
- warn |
| 188 |
default: fail |
| 189 |
type: str |
| 190 |
version_added: 1.8.0 |
| 191 |
password: |
| 192 |
description: |
| 193 |
- Optionally set the user's password to this (plain text) value. |
| 194 |
- To enable an account - I(enabled) - a password must already be |
| 195 |
configured on the account, or you must provide a password here. |
| 196 |
- Use the I(update_password) option to control how a password is checked |
| 197 |
for idempotency. |
| 198 |
type: str |
| 199 |
password_expired: |
| 200 |
description: |
| 201 |
- C(yes) will require the user to change their password at next login. |
| 202 |
- C(no) will clear the expired password flag. |
| 203 |
- This is mutually exclusive with I(password_never_expires). |
| 204 |
type: bool |
| 205 |
password_never_expires: |
| 206 |
description: |
| 207 |
- C(yes) will set the password to never expire. |
| 208 |
- C(no) will allow the password to expire. |
| 209 |
- This is mutually exclusive with I(password_expired). |
| 210 |
type: bool |
| 211 |
postal_code: |
| 212 |
description: |
| 213 |
- Configures the user's postal code / zip code. |
| 214 |
- This is the value set on the C(postalcode) LDAP attribute. |
| 215 |
type: str |
| 216 |
sam_account_name: |
| 217 |
description: |
| 218 |
- The C(sAMAccountName) value to set for the user. |
| 219 |
- If omitted, the I(name) value is used when creating a new user. |
| 220 |
type: str |
| 221 |
spn: |
| 222 |
description: |
| 223 |
- Specifies the service principal name(s) for the account to add, remove |
| 224 |
or set. |
| 225 |
- This is the value set on the C(servicePrincipalName) LDAP attribute. |
| 226 |
- To clear all service principal names, use I(set) with an empty list. |
| 227 |
- See |
| 228 |
R(Setting list option values,ansible_collections.microsoft.ad.docsite.guide_list_values) |
| 229 |
for more information on how to add/remove/set list options. |
| 230 |
aliases: |
| 231 |
- spns |
| 232 |
type: dict |
| 233 |
suboptions: |
| 234 |
add: |
| 235 |
description: |
| 236 |
- The SPNs to add to C(servicePrincipalName). |
| 237 |
type: list |
| 238 |
elements: str |
| 239 |
remove: |
| 240 |
description: |
| 241 |
- The SPNs to remove from C(servicePrincipalName). |
| 242 |
type: list |
| 243 |
elements: str |
| 244 |
set: |
| 245 |
description: |
| 246 |
- The SPNs to set as the only values in C(servicePrincipalName). |
| 247 |
- This will clear out any existing SPNs if not in the specified |
| 248 |
list. |
| 249 |
- Set to an empty list to clear all SPNs on the AD object. |
| 250 |
type: list |
| 251 |
elements: str |
| 252 |
state_province: |
| 253 |
description: |
| 254 |
- Configures the user's state. |
| 255 |
- This is the value set on the C(state) LDAP attribute. |
| 256 |
type: str |
| 257 |
street: |
| 258 |
description: |
| 259 |
- Configures the user's street address. |
| 260 |
- This is the value set on the C(streetaddress) LDAP attribute. |
| 261 |
type: str |
| 262 |
surname: |
| 263 |
description: |
| 264 |
- Configures the user's last name (surname). |
| 265 |
- This is the value set on the C(sn) LDAP attribute. |
| 266 |
aliases: |
| 267 |
- lastname |
| 268 |
type: str |
| 269 |
update_password: |
| 270 |
description: |
| 271 |
- C(always) will always update passwords. |
| 272 |
- C(on_create) will only set the password for newly created users. |
| 273 |
- C(when_changed) will only set the password when changed. |
| 274 |
- Using C(when_changed) will not work if the account is not enabled or |
| 275 |
is expired. |
| 276 |
choices: |
| 277 |
- always |
| 278 |
- on_create |
| 279 |
- when_changed |
| 280 |
default: always |
| 281 |
type: str |
| 282 |
upn: |
| 283 |
description: |
| 284 |
- Configures the User Principal Name (UPN) for the account. |
| 285 |
- This is not required, but is best practice to configure for modern |
| 286 |
versions of Active Directory. |
| 287 |
- The format is C(<username>@<domain>). |
| 288 |
- This is the value set on the C(userPrincipalName) LDAP attribute. |
| 289 |
type: str |
| 290 |
user_cannot_change_password: |
| 291 |
description: |
| 292 |
- C(yes) will prevent the user from changing their password. |
| 293 |
- C(no) will allow the user to change their password. |
| 294 |
type: bool |
| 295 |
notes: |
| 296 |
- See |
| 297 |
R(win_domain_user migration,ansible_collections.microsoft.ad.docsite.guide_migration.migrated_modules.win_domain_user) |
| 298 |
for help on migrating from M(community.windows.win_domain_user) to this |
| 299 |
module. |
| 300 |
- This module must be run on a Windows target host with the |
| 301 |
C(ActiveDirectory) module installed. |
| 302 |
extends_documentation_fragment: |
| 303 |
- microsoft.ad.ad_object |
| 304 |
- ansible.builtin.action_common_attributes |
| 305 |
attributes: |
| 306 |
check_mode: |
| 307 |
support: full |
| 308 |
diff_mode: |
| 309 |
support: full |
| 310 |
platform: |
| 311 |
platforms: |
| 312 |
- windows |
| 313 |
seealso: |
| 314 |
- module: microsoft.ad.domain |
| 315 |
- module: microsoft.ad.domain_controller |
| 316 |
- module: microsoft.ad.group |
| 317 |
- module: microsoft.ad.object |
| 318 |
- module: microsoft.ad.object_info |
| 319 |
- module: microsoft.ad.computer |
| 320 |
- ref: Migration guide <ansible_collections.microsoft.ad.docsite.guide_migration.migrated_modules.win_domain_user> |
| 321 |
description: This module replaces C(community.windows.win_domain_user). See the migration guide for details. |
| 322 |
- module: community.windows.win_domain_user |
| 323 |
author: |
| 324 |
- Jordan Borean (@jborean93) |
| 325 |
|
| 326 |
EXAMPLES: | |
| 327 |
- name: Ensure user bob is present with address information |
| 328 |
microsoft.ad.user: |
| 329 |
identity: bob |
| 330 |
firstname: Bob |
| 331 |
surname: Smith |
| 332 |
company: BobCo |
| 333 |
password: B0bP4ssw0rd |
| 334 |
state: present |
| 335 |
groups: |
| 336 |
set: |
| 337 |
- Domain Admins |
| 338 |
street: 123 4th St. |
| 339 |
city: Sometown |
| 340 |
state_province: IN |
| 341 |
postal_code: 12345 |
| 342 |
country: US |
| 343 |
attributes: |
| 344 |
set: |
| 345 |
telephoneNumber: 555-123456 |
| 346 |
|
| 347 |
- name: Ensure user bob is created and use custom credentials to create the user |
| 348 |
microsoft.ad.user: |
| 349 |
identity: bob |
| 350 |
firstname: Bob |
| 351 |
surname: Smith |
| 352 |
password: B0bP4ssw0rd |
| 353 |
state: present |
| 354 |
domain_username: DOMAIN\admin-account |
| 355 |
domain_password: SomePas2w0rd |
| 356 |
domain_server: [email protected] |
| 357 |
|
| 358 |
- name: Ensure user bob is present in OU ou=test,dc=domain,dc=local |
| 359 |
microsoft.ad.user: |
| 360 |
identity: bob |
| 361 |
password: B0bP4ssw0rd |
| 362 |
state: present |
| 363 |
path: ou=test,dc=domain,dc=local |
| 364 |
groups: |
| 365 |
set: |
| 366 |
- Domain Admins |
| 367 |
- Domain Users |
| 368 |
|
| 369 |
- name: Ensure user bob is absent |
| 370 |
microsoft.ad.user: |
| 371 |
identity: bob |
| 372 |
state: absent |
| 373 |
|
| 374 |
- name: Ensure user has only these spn's defined |
| 375 |
microsoft.ad.user: |
| 376 |
identity: liz.kenyon |
| 377 |
spn: |
| 378 |
set: |
| 379 |
- MSSQLSvc/us99db-svr95:1433 |
| 380 |
- MSSQLSvc/us99db-svr95.vmware.com:1433 |
| 381 |
|
| 382 |
- name: Ensure user has spn added |
| 383 |
microsoft.ad.user: |
| 384 |
identity: liz.kenyon |
| 385 |
spn: |
| 386 |
add: |
| 387 |
- MSSQLSvc/us99db-svr95:2433 |
| 388 |
|
| 389 |
- name: Ensure user is created with delegates and spn's defined |
| 390 |
microsoft.ad.user: |
| 391 |
identity: shmemmmy |
| 392 |
password: The3rubberducki33! |
| 393 |
state: present |
| 394 |
groups: |
| 395 |
set: |
| 396 |
- Domain Admins |
| 397 |
- Domain Users |
| 398 |
- Enterprise Admins |
| 399 |
delegates: |
| 400 |
set: |
| 401 |
- CN=shenetworks,CN=Users,DC=ansible,DC=test |
| 402 |
- CN=mk.ai,CN=Users,DC=ansible,DC=test |
| 403 |
- CN=jessiedotjs,CN=Users,DC=ansible,DC=test |
| 404 |
spn: |
| 405 |
set: |
| 406 |
- MSSQLSvc/us99db-svr95:2433 |
| 407 |
|
| 408 |
# The name option is the name of the AD object as seen in dsa.msc and not the |
| 409 |
# sAMAccountName. For example, this will change the sAMAccountName of the user |
| 410 |
# CN=existing_user,CN=Users,DC=domain,DC=com to 'new_sam_name'. |
| 411 |
# E.g. This will change |
| 412 |
- name: Change the user's sAMAccountName |
| 413 |
microsoft.ad.user: |
| 414 |
name: existing_user |
| 415 |
sam_account_name: new_sam_name |
| 416 |
state: present |
| 417 |
|
| 418 |
# This will rename the AD object that is specified by identity to 'new_name'. |
| 419 |
# The identity value can be the object's GUID, SecurityIdentifier, or |
| 420 |
# sAMAccountName. It is important to use the identity value when renaming or |
| 421 |
# moving a user object to ensure the object is moved/renamed rather than a new |
| 422 |
# one being created. |
| 423 |
- name: Rename user LDAP name |
| 424 |
microsoft.ad.user: |
| 425 |
name: new_name |
| 426 |
identity: '{{ user_obj.object_guid }}' |
| 427 |
state: present |
| 428 |
|
| 429 |
# Like changing the name example above, the identity option is needed to ensure |
| 430 |
# the existing user object specified is moved rather than a new one created at |
| 431 |
# the path specified. |
| 432 |
- name: Move user object to different OU |
| 433 |
microsoft.ad.user: |
| 434 |
name: user |
| 435 |
path: OU=Admins,DC=domain,DC=com |
| 436 |
identity: '{{ user_obj.sid }}' |
| 437 |
state: present |
| 438 |
|
| 439 |
RETURN: |
| 440 |
object_guid: |
| 441 |
description: |
| 442 |
- The C(objectGUID) of the AD object that was created, removed, or edited. |
| 443 |
- If a new object was created in check mode, a GUID of 0s will be |
| 444 |
returned. |
| 445 |
returned: always |
| 446 |
type: str |
| 447 |
sample: d84a141f-2b99-4f08-9da0-ed2d26864ba1 |
| 448 |
distinguished_name: |
| 449 |
description: |
| 450 |
- The C(distinguishedName) of the AD object that was created, removed, or |
| 451 |
edited. |
| 452 |
returned: always |
| 453 |
type: str |
| 454 |
sample: CN=TestUser,CN=Users,DC=domain,DC=test |
| 455 |
sid: |
| 456 |
description: |
| 457 |
- The Security Identifier (SID) of the account managed. |
| 458 |
- If a new user was created in check mode, the SID will be C(S-1-5-0000). |
| 459 |
returned: always |
| 460 |
type: str |
| 461 |
sample: S-1-5-21-4151808797-3430561092-2843464588-1104 |