---
- name: Dependencies installed
  community.general.apk:
    name: git-tiny,npm,pkgconf,glib
    state: latest

- name: Source folder exists
  file:
    path: /usr/local/src
    mode: 0755
    state: directory

- name: Github SSH key installed
  template:
    src: sshkey.j2
    dest: /root/.ssh/id_ed25519
    mode: 0400

- name: 15Five source deployed
  git:
    repo: "git@github.com:15five/engagement.git"
    dest: /usr/local/src/engagement
    accept_hostkey: yes
    update: yes
  ignore_errors: true

- name: Syncthing ignore file installed
  copy:
    src: stignore
    dest: /usr/local/src/engagement/.stignore
    mode: 0775

- name: Environment file installed
  template:
    src: env.j2
    dest: /root/.bashrc
    mode: 0600

- name: Fetched libvips source
  shell:
    chdir: /usr/local/src
    cmd: fetch https://github.com/libvips/libvips/releases/download/v8.12.2/vips-8.12.2.tar.gz

- name: Unpacked libvips source
  shell:
    chdir: /usr/local/src
    cmd: tar zxvf vips-8.12.2.tar.gz

- name: libvips built and installed
  shell:
    chdir: /usr/local/src/libvips-8.12.2
    cmd: "./configure & make & make install"

- name: Lerna and dependencies installed
  shell:
    chdir: /usr/local/src/engagement
    cmd: "npm install -g lerna sequelize sequelize-cli@2.6.0 pg && lerna bootstrap"

- name: Run migrations
  shell:
    chdir: /usr/local/src/engagement/db/emplify
    cmd: "source /root/.bashrc && sequelize db:migrate"

- name: Run migrations
  shell:
    chdir: /usr/local/src/engagement/db/emplify
    cmd: "source /root/.bashrc && sequelize db:migrate"

- name: SSH restarted
  service: name=sshd state=restarted
