---
- name: vérification des variables obligatoire
  fail:
    msg: |
      il faut définir les variables `jibri_user` et
      `jibri_password`, `jitsi_server_host` pour utiliser ce role
  when: (jibri_user is not defined) or
        (jibri_password is not defined) or
        (jitsi_server_host is not defined)

# source: https://github.com/jitsi/jibri#jitsi-debian-repository
- name: Import de la clé GPG
  apt_key:
    id: FFD65A0DA2BEBDEB73D44C8BB4D2D216F1FD7806
    url: https://download.jitsi.org/jitsi-key.gpg.key
    keyring: /etc/apt/trusted.gpg.d/jitsi.gpg

- name: Ajout du depot jitsi
  apt_repository:
    repo: deb [signed-by=/etc/apt/trusted.gpg.d/jitsi.gpg] https://download.jitsi.org stable/
    update_cache: true

- name: install jibri
  apt:
    pkg:
      - jibri
  notify: restart jibri

- name: configure jibri
  template:
    src: jibri.conf
    dest: /etc/jitsi/jibri/jibri.conf
    mode: 0755
  notify: restart jibri

- name: configure xorg
  lineinfile:
    path: /etc/jitsi/jibri/xorg-video-dummy.conf
    regexp: "[^?]Virtual "
    line: "    Virtual 1280 720"
  notify:
    - restart jibri
    - restart jibri-xorg

- name: configure les cookies (fichier)
  copy:
    src: chrome-extension-cookie
    dest: /opt/
    mode: '644'
    directory_mode: '755'
  when:
    - jitsi_cookie_enabled is defined
    - jitsi_cookie_enabled

- name: configure les cookies (template)
  template:
    src: chrome-extension-background.js.j2
    dest: /opt/chrome-extension-cookie/background.js
    mode: '644'
  when:
    - jitsi_cookie_enabled is defined
    - jitsi_cookie_enabled
