---
- block:
  - name: Install the deb OnlyOffice repository key
    apt_key:
      keyserver: {{ onlyoffice_deb_repo_key_server }}
      id: {{ onlyoffice_deb_repo_key }}

  - name: Install the deb Mono repository
    apt_repository:
      repo: '{{ onlyoffice_deb_repo }}'
      state: present
      update_cache: yes

  - name: Install the Mono packages on Deb based distributions
    apt: name={{ onlyoffice_deb_packages }} state=present cache_valid_time=1800

  when: ansible_distribution_file_variety == "Debian"
  tags: onlyoffice

- block:
  - name: Install a letsencrypt acme hook
    template: src=onlyoffice-letsencrypt.sh dest=/usr/lib/acme/hooks/onlyoffice owner=root group=root mode=4555

  - name: Run the letsencrypt acme hook if the certificates are not in place
    shell: /usr/lib/acme/hooks/onlyoffice
    args:
      creates: /var/www/onlyoffice/Data/certs/onlyoffice.key
    register: initialize_onlyoffice_https

  - name: Reconfigure the OnlyOffice service for https
    shell: /var/www/onlyoffice/Tools/default-onlyoffice-ssl.sh
    when: initialize_onlyoffice_https is changed

  when: ansible_distribution_file_variety == "Debian"
  tags: [ 'onlyoffic', 'letsencrypt' ]