---

# See https://nodesource.com/blog/nodejs-v012-iojs-and-the-nodesource-linux-repositories
- name: Ensure script to install NodeSource Node.js 0.12 repo has been executed
  shell: >
    curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
    creates=/etc/apt/sources.list.d/nodesource.list
  sudo: yes

- name: Ensure Node.js 0.12 is installed
  apt:
    pkg: nodejs
    state: present
  sudo: yes

- name: Ensure Shout package is installed
  npm:
    name: shout
    global: yes
    production: yes
    version: 0.51.1
    state: present
  sudo: yes

- name: Ensure JS and JSON syntax checking packages are installed
  npm:
    name: "{{ item }}"
    global: yes
    production: yes
    state: present
  with_items:
    - esprima
    - jsonlint
  sudo: yes

- name: Ensure Shout is configured
  copy:
    src: config.js
    dest: /root/.shout/config.js
    validate: 'esvalidate %s'
  sudo: yes

# TODO Support change of password
- name: Ensure user configuration files are present
  template:
    src: user.json.j2
    dest: /root/.shout/users/{{ item.user }}.json
    force: no # Do not overwrite existing users to not erase networks
    validate: 'jsonlint -q %s'
  with_items: shout_users
  sudo: yes

---

# See https://nodesource.com/blog/nodejs-v012-iojs-and-the-nodesource-linux-repositories
- name: Ensure script to install NodeSource Node.js 0.12 repo has been executed
  shell: >
    curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
    creates=/etc/apt/sources.list.d/nodesource.list
  sudo: yes

- name: Ensure Node.js 0.12 is installed
  apt:
    pkg: nodejs
    state: present
  sudo: yes

- name: Ensure Shout package is installed
  npm:
    name: shout
    global: yes
    production: yes
    version: 0.51.1
    state: present
  sudo: yes

- name: Ensure JS and JSON syntax checking packages are installed
  npm:
    name: "{{ item }}"
    global: yes
    production: yes
    state: present
  with_items:
    - esprima
    - jsonlint
  sudo: yes

- name: Ensure Shout is configured
  copy:
    src: config.js
    dest: /root/.shout/config.js
    validate: 'esvalidate %s'
  sudo: yes

- name: Ensure user configuration directory is present
  file:
    path: /root/.shout/users
    state: directory
  sudo: yes

# TODO Support change of password
- name: Ensure user configuration files are present
  template:
    src: user.json.j2
    dest: /root/.shout/users/{{ item.user }}.json
    force: no # Do not overwrite existing users to not erase networks
    validate: 'jsonlint -q %s'
  with_items: shout_users
  sudo: yes

Make sure user config directory exists before creating user config files
Make sure user config directory exists before creating user config files
