---
-
  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: "Including OS-specific variables"
      ansible.builtin.include_vars: "{{ ansible_os_family }}.yml"
    
    -
      name: "Definining nginx_user"
      ansible.builtin.set_fact:
        nginx_user: "{{ __nginx_user }}"
      when: nginx_user is not defined
    
    # Setup/install tasks.
    -
      name: "Including OS-specific setup-RedHat.yml"
      ansible.builtin.include_tasks: setup-RedHat.yml
      when: ansible_os_family == 'RedHat' or ansible_os_family == 'Rocky' or ansible_os_family == 'AlmaLinux'

    -
      name: "Including OS-specific setup-Ubuntu.yml"
      ansible.builtin.include_tasks: setup-Ubuntu.yml
      when: ansible_distribution == 'Ubuntu'
    
    -
      name: "Including OS-specific setup-Debian.yml"
      ansible.builtin.include_tasks: setup-Debian.yml
      when: ansible_os_family == 'Debian'
    
    -
      name: "Including OS-specific setup-FreeBSD.yml"
      ansible.builtin.include_tasks: setup-FreeBSD.yml
      when: ansible_os_family == 'FreeBSD'
    
    -
      name: "Including OS-specific setup-OpenBSD.yml"
      ansible.builtin.include_tasks: setup-OpenBSD.yml
      when: ansible_os_family == 'OpenBSD'
    
    -
      name: "Including OS-specific setup-Archlinux.yml"
      ansible.builtin.include_tasks: setup-Archlinux.yml
      when: ansible_os_family == 'ArchLinux'
    
    -
      name: "Including OS-specific setup-Suse.yml"
      ansible.builtin.include_tasks: setup-Suse.yml
      when: ansible_os_family == 'Suse'
    
    # Vhost configuration.
    -
      name: "Including OS-specific vhosts.yml"
      ansible.builtin.import_tasks: vhosts.yml
    
    # Nginx setup.
    -
      name: "Copying nginx configuration in place."
      ansible.builtin.template:
        src: "{{ nginx_conf_template }}"
        dest: "{{ nginx_conf_file_path }}"
        owner: root
        group: "{{ root_group }}"
        mode: "0644"
      notify:
        - Reload nginx
    
    -
      name: "Ensuring nginx service is running as configured"
      ansible.builtin.service:
        name: nginx
        state: "{{ nginx_service_state }}"
        enabled: "{{ nginx_service_enabled }}"
