---
-
  name: "Managing progress for {{ ansible_role_name }}"
  when: count_progress | default(false)
  run_once: true
  block:
    -
      name: "Incrementing global progress step counter for {{ ansible_role_name }}"
      ansible.builtin.set_fact:
        global_current_progress_step: "{{ global_current_progress_step | default(0) | int + 1 }}"

    -
      name: "Including progress reporting task for {{ ansible_role_name }}"
      ansible.builtin.include_role:
        name: startcloud.startcloud_roles.progress
      vars:
        _progress_role_is_setup_run: false
        current_progress_step: "{{ global_current_progress_step | default(0) }}"
        progress_description: "{{ progress_role_description | default('Processing ' + ansible_role_name) }}"

-
  name: "Block to Allow Loading of Variables without running task"
  when: run_tasks
  block:
    -
      name: "Setting up SSH"
      block:
        -
          name: "Updating SSH default Shell"
          ansible.windows.win_regedit:
            path: HKLM:\SOFTWARE\OpenSSH
            name: DefaultShell
            data: "{{ ssh_default_shell }}"
            type: string

        -
          name: "Updating SSH Default Shell Command Option"
          ansible.windows.win_regedit:
            path: HKLM:\SOFTWARE\OpenSSH
            name: DefaultShellCommandOption
            data: "{{ ssh_default_shell_option }}"
            type: string

        -
          name: "Creating SSH key for sysprep to provision on start"
          ansible.windows.win_copy:
            src: "id_rsa.pub"
            dest: C:\ProgramData\ssh\administrators_authorized_keys

        -
          name: "Removing inheritance and reset permissions on administrators_authorized_keys"
          ansible.windows.win_acl:
            path: C:\ProgramData\ssh\administrators_authorized_keys
            user: Administrators
            rights: FullControl
            type: allow
            state: present
            inheritance: None

        -
          name: "Setting SYSTEM permissions on administrators_authorized_keys"
          ansible.windows.win_acl:
            path: C:\ProgramData\ssh\administrators_authorized_keys
            user: SYSTEM
            rights: FullControl
            type: allow
            state: present
            inheritance: None

        -
          name: "Configuring SSH Service"
          ansible.windows.win_powershell:
            script: Set-Service -Name 'sshd' -StartupType Automatic

        -
          name: "Configuring Uptime for SSH monitoring"
          block:
            -
              name: "Preparing Uptime"
              ansible.windows.win_copy:
                src: uptime
                dest: "{{ item }}"
              loop: "{{ uptime_files }}"

            -
              name: "Setting permissions on uptime"
              ansible.windows.win_shell: |
                icacls "{{ item }}" /grant Everyone:F
              loop: "{{ uptime_files }}"
