---

- name: ensure up1 user is present
  user:
    name: "up1"
    home: "/srv/up1"
    shell: "/bin/bash"
    state: present

- name: Clone up1 repo
  git:
    repo: https://github.com/Upload/Up1
    dest: /srv/up1/up1
  become: true
  become_user: up1

- name: copy server settings
  template:
    src: server.conf.j2
    dest: /srv/up1/up1/server/server.conf
    owner: up1
    group: www-data
    mode: 0660

- name: copy client settings
  template:
    src: config.js.j2
    dest: /srv/up1/up1/client/config.js
    owner: up1
    group: www-data
    mode: 0660

- name: Install up1 deps
  become: true
  become_user: up1
  npm:
    path: /srv/up1/up1/server


- name: NODE | Install pm2
  npm:
    name: pm2
    global: yes
    production: yes
    state: present

- name: NODE | Start APP
  become: true
  become_user: up1
  shell: pm2 start server.js --name server
  args:
    chdir: /srv/up1/up1/server
  ignore_errors: yes