Debian Codegraph @

ansible_collections/microsoft/ad/tests/integration/targets/setup_domain/tasks/main.yml

raw
1 - name: ensure the ActiveDirectory module is installed
2 ansible.windows.win_feature:
3 name:
4 - RSAT-AD-PowerShell
5 state: present
6
7 - name: check if domain is already set up
8 domain:
9 dns_domain_name: '{{ domain_realm }}'
10 safe_mode_password: '{{ domain_password }}'
11 check_mode: true
12 register: domain_res
13
14 # If the domain is not already set up and this is running under the domain
15 # test target then run the tests for that target, otherwise do the bare
16 # minimum setup. This allows us to do more complex testing for that module
17 # if it is the only one to run.
18 - include_tasks: '{{ (run_domain_test | default(False)) | ternary(role_path ~ "/../domain/tasks/test.yml", "setup.yml") }}'
19 when: domain_res is changed
20
21 # While usually the reboot waits until it is fully done before continuing I've seen Server 2019 in CI still waiting
22 # for things to initialise. By tested if ADWS is available with a simple check we can ensure the host is at least
23 # ready to test AD. Typically I've found it takes about 60 retries so doubling it should cover even an absolute worst# case.
24 - name: post domain setup test for ADWS to come online
25 ansible.windows.win_powershell:
26 parameters:
27 Delay: 5
28 Retries: 120
29 script: |
30 [CmdletBinding()]
31 param (
32 [int]$Delay,
33 [int]$Retries
34 )
35 $Ansible.Changed = $false
36 $attempts = 0
37 $err = $null
38 while ($true) {
39 $attempts++
40 try {
41 Get-ADRootDSE -ErrorAction Stop
42 break
43 }
44 catch {
45 if ($attempts -eq $Retries) {
46 throw
47 }
48 Start-Sleep -Seconds $Delay
49 }
50 }
51 $attempts
52 register: setup_domain_info
53 become: yes
54 become_method: runas
55 become_user: SYSTEM