Deprecated

Removed in 3.0.0

i

Reason:This module has been moved into the C(microsoft.ad) collection. | Alternative:Use the M(microsoft.ad.membership) module instead.

ansible.windows.win_domain_membership (2.3.0) — module

Manage domain/workgroup membership for a Windows host

Authors: Matt Davis (@nitzmahone)

Install collection

Install with ansible-galaxy collection install ansible.windows:==2.3.0


Add to requirements.yml

  collections:
    - name: ansible.windows
      version: 2.3.0

Description

Manages domain membership or workgroup membership for a Windows host. Also supports hostname changes.

This module may require subsequent use of the M(ansible.windows.win_reboot) action if changes are made.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

# 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: false
  tasks:
  - ansible.windows.win_domain_membership:
      dns_domain_name: ansible.vagrant
      hostname: mydomainclient
      domain_admin_user: testguy@ansible.vagrant
      domain_admin_password: password123!
      domain_ou_path: "OU=Windows,OU=Servers,DC=ansible,DC=vagrant"
      state: domain
    register: domain_state

  - ansible.windows.win_reboot:
    when: domain_state.reboot_required
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.


# 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: false
  tasks:
  - ansible.windows.win_domain_membership:
      workgroup_name: mywg
      domain_admin_user: '{{ win_domain_admin_user }}'
      domain_admin_password: '{{ win_domain_admin_password }}'
      state: workgroup

Inputs

    
state:
    choices:
    - domain
    - workgroup
    description:
    - Whether the target host should be a member of a domain or workgroup.
    type: str

hostname:
    description:
    - The desired hostname for the Windows host.
    type: str

domain_ou_path:
    description:
    - The desired OU path for adding the computer object.
    - This is only used when adding the target host to a domain, if it is already a member
      then it is ignored.
    type: str

workgroup_name:
    description:
    - When C(state) is C(workgroup), the name of the workgroup that the Windows host should
      be in.
    type: str

dns_domain_name:
    description:
    - When C(state) is C(domain), the DNS name of the domain to which the targeted Windows
      host should be joined.
    type: str

domain_admin_user:
    description:
    - Username of a domain admin for the target domain (required to join or leave the
      domain).
    required: true
    type: str

domain_admin_password:
    description:
    - Password for the specified C(domain_admin_user).
    type: str

Outputs

reboot_required:
  description: True if changes were made that require a reboot.
  returned: always
  sample: true
  type: bool

See also