microsoft.ad.user module – Manage Active Directory users
Note
This module is part of the microsoft.ad collection (version 1.4.1).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install microsoft.ad
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: microsoft.ad.user
.
Synopsis
Manages Active Directory users and their attributes.
Requirements
The below requirements are needed on the host that executes this module.
ActiveDirectory
PowerShell module
Parameters
Parameter |
Comments |
---|---|
Note that there is not a way to lock an account as an administrator. Accounts are locked due to user actions; as an admin, you may only unlock a locked account. If you wish to administratively disable an account, set enabled to Choices:
|
|
The attributes to either add, remove, or set on the AD object. The value of each attribute option should be a dictionary where the key is the LDAP attribute, e.g. The attribute value(s) can either be the raw string, integer, or bool value to add, remove, or set on the attribute in question. The value can also be a dictionary with the type key set to The The The The String attribute values are compared using a case sensitive match on the AD object being managed. See LDAP attributes help for more information. Default: |
|
A dictionary of all the attributes and their value(s) to add to the AD object being managed if they are not already present. This is used for attributes that can contain multiple values, if the attribute only allows a single value, use set instead. Default: |
|
A dictionary of all the attributes and their value(s) to remove from the AD object being managed if they are present. This is used for attributes that can contain multiple values, if the attribute only allows a single value, use set instead. Default: |
|
A dictionary of all attributes and their value(s) to set on the AD object being managed. This will replace any existing values if they do not match the ones being requested. The order of attribute values are not checked only, only that the values requested are the only values on the object attribute. Set this to null or an empty list to clear any values for the attribute. Default: |
|
Configures the user’s city. This is the value set on the |
|
Configures the user’s company name. This is the value set on the |
|
Configures the user’s country code. Note that this is a two-character ISO 3166 code. This is the value set on the |
|
The principal objects that the current AD object can trust for delegation to either add, remove or set. The values for each sub option must be specified as a distinguished name This is the value set on the This is a highly sensitive attribute as it allows the principals specified to impersonate any account when authenticating with the AD computer object being managed. To clear all principals, use set with an empty list. See Setting list option values for more information on how to add/remove/set list options. |
|
The AD objects by their Any existing principals not specified by add will be untouched unless specified by remove or not in set. |
|
The AD objects by their Any existing principals not specified by remove will be untouched unless set is defined. |
|
The AD objects by their This will remove any existing principals if not specified in this list. Specify an empty list to remove all principals allowed to delegate. |
|
The description of the AD object to set. This is the value set on the |
|
The display name of the AD object to set. This is the value of the |
|
The password for domain_username. |
|
Specified the Active Directory Domain Services instance to connect to. Can be in the form of an FQDN or NetBIOS name. If not specified then the value is based on the default domain of the computer running PowerShell. |
|
The username to use when interacting with AD. If this is not set then the user that is used for authentication will be the connection user. Ansible will be unable to use the connection user unless auth is Kerberos with credential delegation or CredSSP, or become is used on the task. |
|
Configures the user’s email address. This is a record in AD and does not do anything to configure any email servers or systems. This is the value set on the |
|
The default when creating a new is Choices:
|
|
Configures the user’s first name (given name). This is the value set on the |
|
Specifies the group membership the user is added, removed, or set to. To clear all group memberships, use set with an empty list. Note that users cannot be removed from their principal group (for example, “Domain Users”). Attempting to do so will display a warning. See Setting list option values for more information on how to add/remove/set list options. |
|
The groups to add the user to. |
|
Controls what happens when a group specified by
Choices:
|
|
The groups to remove the user from. |
|
The only groups the user is a member of. This will clear out any existing groups if not in the specified list. Set to an empty list to clear all group membership of the user. |
|
The identity of the AD object used to find the AD object to manage. Must be specified if name is not set, when trying to rename the object with a new name, or when trying to move the object into a different path. The identity can be in the form of a GUID representing the If omitted, the AD object to managed is selected by the |
|
The If identity is specified, and the name of the object it found does not match this value, the object will be renamed. This if identity must be set to find the object to manage. This is not always going to be the same as the |
|
Optionally set the user’s password to this (plain text) value. To enable an account - enabled - a password must already be configured on the account, or you must provide a password here. Use the update_password option to control how a password is checked for idempotency. |
|
This is mutually exclusive with password_never_expires. Choices:
|
|
This is mutually exclusive with password_expired. Choices:
|
|
The path of the OU or the container where the new object should exist in. If creating a new object, the new object will be created at the path specified. If no path is specified then the If managing an existing object found by identity, the path of the found object will be moved to the one specified by this option. If no path is specified, the object will not be moved. The modules microsoft.ad.computer, microsoft.ad.user, and microsoft.ad.group have their own default path that is configured on the Active Directory domain controller. This can be set to |
|
Configures the user’s postal code / zip code. This is the value set on the |
|
Marks the object as protected from accidental deletion. This applies a deny access right from deleting the object normally and the protection needs to be removed before the object can be deleted through the GUI or any other tool outside Ansible. Using state=absent will still delete the AD object even if it is marked as protected from deletion. Choices:
|
|
The If omitted, the name value is used when creating a new user. |
|
Specifies the service principal name(s) for the account to add, remove or set. This is the value set on the To clear all service principal names, use set with an empty list. See Setting list option values for more information on how to add/remove/set list options. |
|
The SPNs to add to |
|
The SPNs to remove from |
|
The SPNs to set as the only values in This will clear out any existing SPNs if not in the specified list. Set to an empty list to clear all SPNs on the AD object. |
|
Set to Set to The option name must be set when state=present. Using Choices:
|
|
Configures the user’s state. This is the value set on the |
|
Configures the user’s street address. This is the value set on the |
|
Configures the user’s last name (surname). This is the value set on the |
|
Using Choices:
|
|
Configures the User Principal Name (UPN) for the account. This is not required, but is best practice to configure for modern versions of Active Directory. The format is This is the value set on the |
|
Choices:
|
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: full |
Can run in check_mode and return changed status prediction without modifying target |
|
Support: full |
Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode |
|
Platform: windows |
Target OS/families that can be operated against |
Notes
Note
See win_domain_user migration for help on migrating from community.windows.win_domain_user to this module.
Some LDAP attributes can have only a single value set while others can have multiple. Some attributes are also read only and cannot be changed. It is recommended to look at the schema metadata for an attribute where
System-Only
are read only values andIs-Single-Value
are attributes with only 1 value.Attempting to set multiple values to a
Is-Single-Value
attribute results in undefined behaviour.If running on a server that is not a Domain Controller, credential delegation through CredSSP or Kerberos with delegation must be used or the domain_username, domain_password must be set.
See Also
See also
- microsoft.ad.domain
Ensures the existence of a Windows domain.
- microsoft.ad.domain_controller
Manage domain controller/member server state for a Windows host.
- microsoft.ad.group
Manage Active Directory group objects.
- microsoft.ad.object
Manage Active Directory objects.
- microsoft.ad.object_info
Gather information an Active Directory object.
- microsoft.ad.computer
Manage Active Directory computer objects.
- Migration guide
This module replaces
community.windows.win_domain_user
. See the migration guide for details.- community.windows.win_domain_user
Manages Windows Active Directory user accounts.
Examples
- name: Ensure user bob is present with address information
microsoft.ad.user:
name: bob
firstname: Bob
surname: Smith
company: BobCo
password: B0bP4ssw0rd
state: present
groups:
set:
- Domain Admins
street: 123 4th St.
city: Sometown
state_province: IN
postal_code: 12345
country: US
attributes:
set:
telephoneNumber: 555-123456
- name: Ensure user bob is created and use custom credentials to create the user
microsoft.ad.user:
name: bob
firstname: Bob
surname: Smith
password: B0bP4ssw0rd
state: present
domain_username: DOMAIN\admin-account
domain_password: SomePas2w0rd
domain_server: [email protected]
- name: Ensure user bob is present in OU ou=test,dc=domain,dc=local
microsoft.ad.user:
name: bob
password: B0bP4ssw0rd
state: present
path: ou=test,dc=domain,dc=local
groups:
set:
- Domain Admins
- Domain Users
- name: Ensure user bob is absent
microsoft.ad.user:
name: bob
state: absent
- name: Ensure user has only these spn's defined
microsoft.ad.user:
name: liz.kenyon
spn:
set:
- MSSQLSvc/us99db-svr95:1433
- MSSQLSvc/us99db-svr95.vmware.com:1433
- name: Ensure user has spn added
microsoft.ad.user:
name: liz.kenyon
spn:
add:
- MSSQLSvc/us99db-svr95:2433
- name: Ensure user is created with delegates and spn's defined
microsoft.ad.user:
name: shmemmmy
password: The3rubberducki33!
state: present
groups:
set:
- Domain Admins
- Domain Users
- Enterprise Admins
delegates:
set:
- CN=shenetworks,CN=Users,DC=ansible,DC=test
- CN=mk.ai,CN=Users,DC=ansible,DC=test
- CN=jessiedotjs,CN=Users,DC=ansible,DC=test
spn:
set:
- MSSQLSvc/us99db-svr95:2433
# The name option is the name of the AD object as seen in dsa.msc and not the
# sAMAccountName. For example, this will change the sAMAccountName of the user
# CN=existing_user,CN=Users,DC=domain,DC=com to 'new_sam_name'.
# E.g. This will change
- name: Change the user's sAMAccountName
microsoft.ad.user:
name: existing_user
sam_account_name: new_sam_name
state: present
# This will rename the AD object that is specified by identity to 'new_name'.
# The identity value can be the object's GUID, SecurityIdentifier, or
# sAMAccountName. It is important to use the identity value when renaming or
# moving a user object to ensure the object is moved/renamed rather than a new
# one being created.
- name: Rename user LDAP name
microsoft.ad.user:
name: new_name
identity: '{{ user_obj.object_guid }}'
state: present
# Like changing the name example above, the identity option is needed to ensure
# the existing user object specified is moved rather than a new one created at
# the path specified.
- name: Move user object to different OU
microsoft.ad.user:
name: user
path: OU=Admins,DC=domain,DC=com
identity: '{{ user_obj.sid }}'
state: present
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
The Returned: always Sample: |
|
The If a new object was created in check mode, a GUID of 0s will be returned. Returned: always Sample: |
|
The Security Identifier (SID) of the account managed. If a new user was created in check mode, the SID will be Returned: always Sample: |