- name: ensure time is in sync hosts: windows gather_facts: no tasks: - name: get current host datetime command: date +%s changed_when: False delegate_to: localhost run_once: True register: local_time - name: set datetime on Windows ansible.windows.win_powershell: parameters: SecondsSinceEpoch: '{{ local_time.stdout | trim }}' script: | param($SecondsSinceEpoch) $utc = [System.DateTimeKind]::Utc $epoch = New-Object -TypeName System.DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, 0, $utc $date = $epoch.AddSeconds($SecondsSinceEpoch) Set-Date -Date $date - name: run microsoft.ad.membership tests hosts: TEST gather_facts: no tasks: - set_fact: get_result_script: | $Ansible.Changed = $false $cs = Get-CimInstance -ClassName Win32_ComputerSystem -Property DNSHostName, Domain, PartOfDomain, Workgroup $domainName = if ($cs.PartOfDomain) { try { [System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().Name } catch [System.Security.Authentication.AuthenticationException] { $cs.Domain } } else { $null } [PSCustomObject]@{ HostName = $cs.DNSHostName NetbiosName = $env:COMPUTERNAME PartOfDomain = $cs.PartOfDomain DnsDomainName = $domainName WorkgroupName = $cs.Workgroup } get_ad_result_script: | $Ansible.Changed = $false Get-ADComputer -Filter { Name -ne 'DC' } -Properties DistinguishedName, DNSHostName, Name, Enabled | Select-Object -Property @( 'DistinguishedName' @{ N = 'DNSHostName'; E = { $_.DNSHostName.Substring(0, $_.DNSHostName.IndexOf('.')) } } 'Name' 'Enabled' ) - import_tasks: tasks/main.yml - import_tasks: tasks/join_with_name_conflict.yml