---
- name: Dependencies installed
  community.general.pkgng:
    name: "ffmpeg"
    state: latest

- name: Timelapse www folder exists
  file:
    path: /var/www/timelapse
    owner: root
    mode: 0755
    state: directory

- name: Index html file installed
  copy:
    src: "index.html"
    dest: "/var/www/timelapse/index.html"
    mode: 0644
  notify: Nginx restarted

- name: East cam file linked
  file: src=/media/photos/webcams/timelapse/east-cam.mp4 dest=/var/www/timelapse/east-cam.mp4 state=link

- name: West cam file linked
  file: src=/media/photos/webcams/timelapse/west-cam.mp4 dest=/var/www/timelapse/west-cam.mp4 state=link

- name: Nginx conf file installed
  copy:
    src: "nginx.conf"
    dest: "/usr/local/etc/nginx/locations/timelapse.conf"
    mode: 0644
  notify: Nginx restarted

- name: timelapse_go script installed
  copy:
    src: "timelapse_go.sh"
    dest: /usr/local/bin/timelapse_go
    mode: 0775

- name: Run timelapse_go every 12 hours
  ansible.builtin.cron:
    name: "timelapse_go"
    hour: "*/12"
    job: "/usr/local/bin/timelapse_go > /dev/null"
