---
# tasks file for nodejs

- name: Assertions
  assert:
    that:
        - ansible_os_family == 'Debian'
        - ansible_lsb.codename in ['buster', 'jessie', 'sid', 'stretch', 'trusty', 'xenial', 'yakkety', 'zesty']
        - nodejs_version in [6, 8]

- name: APT install prerequisites
  apt:
      name: apt-transport-https
      state: present
      update_cache: True
      cache_valid_time: 3600

- name: Add APT repository key
  apt_key:
      url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
      state: present

- name: Add APT repository
  apt_repository:
      repo: |
          deb https://deb.nodesource.com/node_{{ nodejs_version }}.x {{ ansible_lsb.codename }} main
      state: present
      update_cache: True

- name: APT install
  apt:
      name: nodejs
      state: present
      update_cache: True
      cache_valid_time: 3600
