---
- name: Install rsync
  apt:
    name: rsync
    state: present
    update_cache: yes

- name: Ensure website directory exists
  file:
    path: /opt/website
    state: directory
    mode: "0755"

- name: Ensure website html directory exists
  file:
    path: /opt/website/html
    state: directory
    mode: "0755"

- name: Copy website build files
  synchronize:
    src: "{{ playbook_dir }}/../../website/build/"
    dest: /opt/website/html/
    delete: yes
    recursive: yes
  delegate_to: localhost
  become: no

- name: Deploy nginx configuration
  template:
    src: nginx.conf.j2
    dest: /opt/website/nginx.conf
    mode: "0644"

- name: Deploy website docker-compose
  template:
    src: docker-compose.yml.j2
    dest: /opt/website/docker-compose.yml
    mode: "0644"

- name: Start website container
  shell: cd /opt/website && docker compose down && docker compose up -d
  args:
    chdir: /opt/website
