---

# Load distribution specific variables
- include_vars: "{{ item }}"
  with_first_found:
    - "{{ role_path }}/vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
    - "{{ role_path }}/vars/{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
    - "{{ role_path }}/vars/{{ ansible_distribution }}.yml"
    - "{{ role_path }}/vars/{{ ansible_os_family }}.yml"
  tags: kimai

# Detect installed version (if any)
- block:
    - import_tasks: ../includes/webapps_set_install_mode.yml
      vars:
        - root_dir: "{{ kimai_root_dir }}"
        - version: "{{ kimai_version }}"
    - set_fact: kimai_install_mode={{ (install_mode == 'upgrade' and not kimai_manage_upgrade) | ternary('none',install_mode) }}
    - set_fact: kimai_current_version={{ current_version | default('') }}
  tags: kimai

# Create a random pass for the DB if needed
- block:
    - import_tasks: ../includes/get_rand_pass.yml
      vars:
        - pass_file: "{{ kimai_root_dir }}/meta/ansible_dbpass"
    - set_fact: kimai_db_pass={{ rand_pass }}
  when: kimai_db_pass is not defined
  tags: kimai

# Create a random app secret if needed
- block:
    - import_tasks: ../includes/get_rand_pass.yml
      vars:
        - pass_file: "{{ kimai_root_dir }}/meta/ansible_secret_key"
    - set_fact: kimai_secret_key={{ rand_pass }}
  when: kimai_secret_key is not defined
  tags: kimai

# Create a random admin pass if needed
- block:
    - import_tasks: ../includes/get_rand_pass.yml
      vars:
        - pass_file: "{{ kimai_root_dir }}/meta/ansible_admin_pass"
    - set_fact: kimai_admin_pass={{ rand_pass }}
  when: kimai_admin_pass is not defined
  tags: kimai
