# Args:

- name: install nodesource key
  apt_key: url=https://deb.nodesource.com/gpgkey/nodesource.gpg.key state=present

- name: install nodesource repository
  apt_repository: repo='deb https://deb.nodesource.com/node_0.12 trusty main' state=present

- name: install node
  apt: name={{ item }} state=present
  with_items:
    - nodejs
    - jq
    - build-essential

- name: fix node binary name
  command: update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
  args:
    creates: /usr/bin/node

- name: accept self signed certificates
  lineinfile: dest=/root/.bashrc line="export NODE_TLS_REJECT_UNAUTHORIZED=0"
  when:
    - is_development_environment

- name: check installed global npm modules
  shell: cat /usr/lib/node_modules/{{ item.name }}/package.json | jq -r '.version'
  with_items:
    - { name: forever, version: 0.14.2 }
    - { name: nodemon, version: 1.3.7 }
    - { name: json, version: 9.0.3 }
    - { name: node-gyp, version: 3.2.1 }
  register: result
  failed_when: no
  changed_when: result.stdout != "{{ item.version }}"

- name: install global npm modules
  npm: name={{ item.item.name }} version={{ item.item.version }} global=yes state=present
  with_items: result.results
  when: item.changed

# Args:

- name: install nodesource key
  apt_key: url=https://deb.nodesource.com/gpgkey/nodesource.gpg.key state=present

- name: install nodesource repository
  apt_repository: repo='deb https://deb.nodesource.com/node_0.12 trusty main' state=present

- name: install node
  apt: name={{ item }} state=present
  with_items:
    - nodejs
    - jq
    - build-essential

- name: fix node binary name
  command: update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
  args:
    creates: /usr/bin/node

- name: accept self signed certificates
  lineinfile: dest=/root/.bashrc line="export NODE_TLS_REJECT_UNAUTHORIZED=0"
  when:
    - is_development_environment

- name: check installed global npm modules
  shell: cat /usr/lib/node_modules/{{ item.name }}/package.json | jq -r '.version'
  with_items:
    - { name: forever, version: 0.14.2 }
    - { name: nodemon, version: 1.3.7 }
    - { name: json, version: 9.0.3 }
  register: result
  failed_when: no
  changed_when: result.stdout != "{{ item.version }}"

- name: install global npm modules
  npm: name={{ item.item.name }} version={{ item.item.version }} global=yes state=present
  with_items: result.results
  when: item.changed

Remove useless install of the node-gyp npm global package.
Remove useless install of the node-gyp npm global package.
