---
- name: Install requirements
  ansible.builtin.apt:
    name:
      - git
      - dialog
    state: present

- name: Test if Yunohost is already installed
  ansible.builtin.stat: path=/etc/yunohost/installed
  register: ynh_file_install

- name: Download Yunohost install script
  ansible.builtin.get_url:
    url: "{{ ynh_install_script_url }}"
    dest: /tmp/install_yunohost.sh
    mode: 700
  when: ynh_file_install.stat.exists == False

- name: Launch Yunohost install script
  ansible.builtin.command: /tmp/install_yunohost.sh -a
  when: ynh_file_install.stat.exists == False

- name: Launch Yunohost postinstall
  ansible.builtin.shell: "
    yunohost tools postinstall \
      --domain {{ ynh_main_domain }} \
      --password {{ ynh_admin_password }} \
      {% if ynh_ignore_dyndns_server == True %} --ignore-dyndns {% endif %}"
  when: ynh_file_install.stat.exists == False

- name: Create extra domains
  ansible.builtin.include: domains.yml
  when: ynh_extra_domains

- name: Run first Yunohost diagnosis
  ansible.builtin.shell: yunohost diagnosis run

- name: Install domain certificates
  ansible.builtin.shell: yunohost domain cert-install
  changed_when: False

- name: Add Yunohost users
  ansible.builtin.include: users.yml
  when: ynh_users

- name: Install Yunohost apps
  ansible.builtin.include: apps.yml
  when: ynh_apps