- name: Install NodeJS
  hosts: all
  gather_facts: True
  vars:
    node_version: 7.10.0
  tasks:
    - name: Install dependencies
      apt: pkg={{ item }} update_cache=yes cache_valid_time=3600
      with_items:
        - git
        - curl
        - build-essential
        - libssl-dev

    - name: Download NodeJS setup script
      get_url:
        url=https://deb.nodesource.com/setup_7.x
        dest=/tmp/install-nodejs-{{node_version}}.sh

    - name: Run NodeJS setup script
      shell: bash install-nodejs-{{node_version}}.sh chdir=/tmp executable=/bin/bash

    - name: Install NodeJS package
      apt: pkg={{ item }} update_cache=yes state=latest
      with_items:
        - nodejs