---

- include_vars: "{{ item }}"
  with_first_found:
    - vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml
    - vars/{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml
    - vars/{{ ansible_distribution }}.yml
    - vars/{{ ansible_os_family }}.yml
  tags: matrix

# Detect installed version (if any)
- block:
    - import_tasks: ../includes/webapps_set_install_mode.yml
      vars:
        - root_dir: "{{ synapse_root_dir }}"
        - version: "{{ synapse_version }}"
    - set_fact: synapse_install_mode={{ (install_mode == 'upgrade' and not synapse_manage_upgrade) | ternary('none',install_mode) }}
    - set_fact: synapse_current_version={{ current_version | default('') }}
  tags: matrix

- when: synapse_pg_db_pass is not defined
  block:
    - import_tasks: ../includes/get_rand_pass.yml
      vars:
        - pass_file: "{{ synapse_root_dir }}/meta/ansible_dbpass"
    - set_fact: synapse_pg_db_pass={{ rand_pass }}
  tags: matrix

- block:
    - import_tasks: ../includes/get_rand_pass.yml
      vars:
        - pass_file: "{{ synapse_root_dir }}/meta/ansible_macaroon_key"
    - set_fact: synapse_macaroon_key={{ rand_pass }}
  tags: matrix

- block:
    - import_tasks: ../includes/get_rand_pass.yml
      vars:
        - pass_file: "{{ synapse_root_dir }}/meta/ansible_form_secret"
    - set_fact: synapse_form_secret={{ rand_pass }}
  tags: matrix

- name: Check if the old venv is present
  stat: path={{ synapse_root_dir }}/lib
  register: synapse_old_venv
  tags: matrix
