---
-
  name: "Managing progress for {{ ansible_role_name }} (Step 1 of 1)"
  when: count_progress | default(false)
  run_once: true
  block:
    -
      name: "Incrementing global progress step counter for {{ ansible_role_name }} (Step 1)"
      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 }} (Step 1)"
      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 + ' - Step 1') }}"

-
  name: "Block to Allow Loading of Variables without running task"
  when: run_tasks
  block:
    -
      name: "Disabling NFS, Exim and Cockpit, reboot to fully apply"
      when: not ansible_module_running_in_container
      ansible.builtin.service:
        name: "{{ item }}"
        state: stopped
        enabled: false
      loop: "{{ lockdown }}"
    
    -
      name: "Changing startcloud Password"
      when: lockdown_use_settings_password
      ansible.builtin.user:
        name: "startcloud"
        state: present
        password: "{{ vagrant_user_pass | password_hash('sha512') }}"
    
    -
      name: "Changing startcloud Password"
      when: not lockdown_use_settings_password
      ansible.builtin.user:
        name: "startcloud"
        state: present
        password: "{{ lockdown_new_password | password_hash('sha512') }}"
    
    -
      name: "Generating an OpenSSH keypair with the default values"
      community.crypto.openssh_keypair:
        owner: startcloud
        group: startcloud
        path: /home/startcloud/.ssh/id_ssh_rsa
    
    -
      name: "Setting ownership of SSH files"
      ansible.builtin.file:
        owner: startcloud
        group: startcloud
        path: "{{ item }}"
        state: directory
        recurse: true
      with_items:
        - "/home/startcloud/.ssh"
    
    -
      name: "Copying the public key to the remote server"
      ansible.posix.authorized_key:
        user: startcloud
        state: present
        exclusive: false
        key: "{{ lookup('file', '/home/startcloud/.ssh/id_ssh_rsa.pub') }}"
    
    -
      name: Reset ssh connection to apply user changes.
      ansible.builtin.meta: reset_connection

-
  name: "Cleaning up specified sensitive files"
  when: lockdown_file_cleanups_list is defined and lockdown_file_cleanups_list | length > 0 and lockdown_cleanup_debug_files | default(false)
  ansible.builtin.file:
    path: "{{ item }}"
    state: absent
  loop: "{{ lockdown_file_cleanups_list }}"
  loop_control:
    label: "{{ item }}"
