---
-
  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: "Creating the group {{ service_group }}"
      ansible.builtin.group:
        name: "{{ service_group }}"
        state: present
    
    -
      name: "Adding user to groups: {{ service_user }}"
      ansible.builtin.user:
        name: "{{ service_user }}"
        shell: /bin/bash
        home: "{{ service_home_dir }}"
        groups:
          - "{{ service_group }}"
          - sudo
        append: yes
        createhome: no
        system: yes
    -
      name: "Adding startcloud to groups: {{ service_group }}"
      ansible.builtin.user:
        name: "{{ settings.vagrant_user }}"
        groups: "{{ service_group }}"
        append: true

    -
      name: "Adding user to sudoers: {{ service_user }}"
      ansible.builtin.lineinfile:
        path: "/etc/sudoers.d/{{ service_user }}"
        line: "{{ service_user }} ALL=(ALL:ALL) NOPASSWD:ALL"
        mode: '0644'
        create: true
    
    -
      name: "Adding soft nofile limits to in limits.conf for user: {{ service_user }}"
      community.general.pam_limits:
        domain: "{{ service_user }}"
        limit_type: soft
        limit_item: nofile
        value: "{{ service_user_soft_limit }}"
    
    -
      name: "Adding hard nofile limits to in limits.conf for user: {{ service_user }} "
      community.general.pam_limits:
        domain: "{{ service_user }}"
        limit_type: hard
        limit_item: nofile
        value: "{{ service_user_hard_limit }}"
    
    -
      name: "Creating Installation Directories"
      ansible.builtin.file:
        path: "{{ item }}"
        state: directory
        owner: "{{ service_user }}"
        mode: '0755'
      with_items:
        - "{{ service_home_dir }}/.ansible/tmp"
