---

# Detect installed version (if any)
- block:
    - import_tasks: ../includes/webapps_set_install_mode.yml
      vars:
        - root_dir: "{{ n8n_root_dir }}"
        - version: "{{ n8n_version }}"
    - set_fact: n8n_install_mode={{ (install_mode == 'upgrade' and not n8n_manage_upgrade) | ternary('none',install_mode) }}
    - set_fact: n8n_current_version={{ current_version | default('') }}
  tags: n8n

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

# Random encryption key
- block:
    - import_tasks: ../includes/get_rand_pass.yml
      vars:
        - pass_file: "{{ n8n_root_dir }}/meta/ansible_secret_key"
    - set_fact: n8n_secret_key={{ rand_pass }}
  when: n8n_secret_key is not defined
  tags: n8n
