---
- name: Initial services check
  block:
    - name: Initial reboot
      ansible.windows.win_reboot:
        reboot_timeout: 3600

    - name: Wait for AD services
      community.windows.win_wait_for_process:
        process_name_exact: Microsoft.ActiveDirectory.WebServices
        pre_wait_delay: 60
        state: present
        timeout: 600
        sleep: 10
  rescue:
    - name: Note initial failure
      ansible.builtin.debug:
        msg: "Initial services check failed, rebooting again..."

- name: Secondary services check
  block:
    - name: Reboot again
      ansible.windows.win_reboot:
        reboot_timeout: 3600

    - name: Wait for AD services again
      community.windows.win_wait_for_process:
        process_name_exact: Microsoft.ActiveDirectory.WebServices
        pre_wait_delay: 60
        state: present
        timeout: 600
        sleep: 10
  rescue:
    - name: Note secondary failure
      failed_when: true
      ansible.builtin.debug:
        msg: "Secondary services check failed, bailing out..."
