---

# TODO
# source code is not yet checked out from git

- name: Install docker-compose
  apt: name=docker-compose

- name: Install systemd unit
  template: src=workadventure.service.j2 dest=/lib/systemd/system/workadventure.service
  notify:
  - Reload systemd
  - Restart workadventure

- name: Ensure certificates are available
  command: openssl req -x509 -nodes -newkey rsa:2048 -keyout /etc/nginx/ssl/{{ workadventure_domain }}.key -out /etc/nginx/ssl/{{ workadventure_domain }}.crt -days 730 -subj "/CN={{ workadventure_domain }}" creates=/etc/nginx/ssl/{{ workadventure_domain }}.crt
  notify: Restart nginx

- name: Configure certificate manager for workadventure
  template: src=certs.j2 dest=/etc/acertmgr/{{ workadventure_domain }}.conf
  notify: Run acertmgr

- name: Configure vhost
  template: src=vhost.j2 dest=/etc/nginx/sites-available/workadventure
  notify: Restart nginx

- name: Enable vhost
  file: src=/etc/nginx/sites-available/workadventure dest=/etc/nginx/sites-enabled/workadventure state=link
  notify: Restart nginx

- name: Enable workadventure
  service: name=workadventure enabled=yes