Documentation

win_domain_membership - Manage domain/workgroup membership for a Windows host

New in version 2.3.

Synopsis

  • Manages domain membership or workgroup membership for a Windows host. Also supports hostname changes. This module may require subsequent use of the win_reboot action if changes are made.

Options

parameter required default choices comments
dns_domain_name
no
when state is domain, the DNS name of the domain to which the targeted Windows host should be joined
domain_admin_password
no
password for the specified domain_admin_user
domain_admin_user
yes
username of a domain admin for the target domain (required to join or leave the domain)
hostname
no
the desired hostname for the Windows host
state
no
  • domain
  • workgroup
whether the target host should be a member of a domain or workgroup
workgroup_name
no
when state is workgroup, the name of the workgroup that the Windows host should be in

Examples

# host should be a member of domain ansible.vagrant; module will ensure the hostname is mydomainclient
# and will use the passed credentials to join domain if necessary.
# Ansible connection should use local credentials if possible.
# If a reboot is required, the second task will trigger one and wait until the host is available.
- hosts: winclient
  gather_facts: no
  tasks:
  - win_domain_membership:
      dns_domain_name: ansible.vagrant
      hostname: mydomainclient
      domain_admin_user: testguy@ansible.vagrant
      domain_admin_password: password123!
      state: domain
    register: domain_state

  - win_reboot:
    when: domain_state.reboot_required



# Host should be in workgroup mywg- module will use the passed credentials to clean-unjoin domain if possible.
# Ansible connection should use local credentials if possible.
# The domain admin credentials can be sourced from a vault-encrypted variable
- hosts: winclient
  gather_facts: no
  tasks:
  - win_domain_membership:
      workgroup_name: mywg
      domain_admin_user: '{{ win_domain_admin_user }}'
      domain_admin_password: '{{ win_domain_admin_password }}'
      state: workgroup

Return Values

Common return values are documented here Return Values, the following are the fields unique to this module:

name description returned type sample
reboot_required True if changes were made that require a reboot. always boolean True


Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Support

This module is maintained by those with core commit privileges

For more information on what this means please read Module Support

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Helping Testing PRs and Developing Modules.