- name: Add repository deb.nodesource.com/node_4.x
  become: yes
  become_user: root
  apt_repository:
    repo: deb https://deb.nodesource.com/node_4.x trusty main
    state: present
    update_cache: yes
  tags: [nodejs]

- name: Install nodejs packages
  become: yes
  become_user: root
  apt:
    name: '{{item}}'
    state: latest
  with_items:
    - nodejs
  tags: [nodejs]

- name: Install npm packages
  become: yes
  become_user: root
  npm:
    name: '{{item}}'
    global: yes
  with_items:
    - npm
  tags: [nodejs]

- name: Add apt key for deb.nodesource.com/node_4.x
  become: yes
  become_user: root
  apt_key:
    url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
    state: present
  tags: [nodejs]

- name: Add repository deb.nodesource.com/node_4.x
  become: yes
  become_user: root
  apt_repository:
    repo: deb https://deb.nodesource.com/node_4.x trusty main
    state: present
    update_cache: yes
  tags: [nodejs]

- name: Install nodejs packages
  become: yes
  become_user: root
  apt:
    name: '{{item}}'
    state: latest
  with_items:
    - nodejs
  tags: [nodejs]

- name: Install npm packages
  become: yes
  become_user: root
  npm:
    name: '{{item}}'
    global: yes
  with_items:
    - npm
  tags: [nodejs]

Add apt key for the repositority
[nodejs] Add apt key for the repositority
