---

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

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

- name: NODE | Install gancio
  npm:
    executable: /usr/bin/npm --unsafe-perm=true --allow-root
    name: gancio
    global: yes
    production: yes
    state: present

- name: Copy settings
  template:
    src: config.json.j2
    dest: /srv/gancio/config.json
    owner: gancio
    group: gancio
    mode: 0660

- name: NODE | Start APP
  become: true
  become_user: gancio
  shell: pm2 start gancio -- start --config config.json
  args:
    chdir: /srv/gancio
  ignore_errors: yes
