# Install Node.js using packages crafted by NodeSource
---
- name: Ensure the system can use the HTTPS transport for APT
  stat:
    path: /usr/lib/apt/methods/https
  register: apt_https_transport

- name: Install HTTPS transport for APT
  apt:
    pkg: apt-transport-https
    state: installed
  when: not apt_https_transport.stat.exists

- name: Import the NodeSource GPG key into apt
  apt_key:
    url: https://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0x1655A0AB68576280
    id: "68576280"
    state: present

- name: Add NodeSource deb repository
  apt_repository:
    repo: 'deb https://deb.nodesource.com/node_{{ debian_repo_version }} {{ ansible_distribution_release }} main'
    state: present

- name: Add NodeSource deb-src repository
  apt_repository:
    repo: 'deb-src https://deb.nodesource.com/node_{{ debian_repo_version }} {{ ansible_distribution_release }} main'
    state: present

- name: Add NodeSource repository preferences
  template:
    src: etc/apt/preferences.d/deb_nodesource_com_node.pref.2
    dest: /etc/apt/preferences.d/deb_nodesource_com_node.pref

- name: Install Node.js
  apt:
    pkg:
      - nodejs
    state: installed
    update_cache: yes

# Install Node.js using packages crafted by NodeSource
---
- name: Ensure the system can use the HTTPS transport for APT
  stat:
    path: /usr/lib/apt/methods/https
  register: apt_https_transport

- name: Install HTTPS transport for APT
  apt:
    pkg: apt-transport-https
    state: installed
  when: not apt_https_transport.stat.exists

- name: Install GPG
  apt:
    pkg: gnupg
    state: installed

- name: Import the NodeSource GPG key into apt
  apt_key:
    url: https://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0x1655A0AB68576280
    id: "68576280"
    state: present

- name: Add NodeSource deb repository
  apt_repository:
    repo: 'deb https://deb.nodesource.com/node_{{ debian_repo_version }} {{ ansible_distribution_release }} main'
    state: present

- name: Add NodeSource deb-src repository
  apt_repository:
    repo: 'deb-src https://deb.nodesource.com/node_{{ debian_repo_version }} {{ ansible_distribution_release }} main'
    state: present

- name: Add NodeSource repository preferences
  template:
    src: etc/apt/preferences.d/deb_nodesource_com_node.pref.2
    dest: /etc/apt/preferences.d/deb_nodesource_com_node.pref

- name: Install Node.js
  apt:
    pkg:
      - nodejs
    state: installed
    update_cache: yes

Make sure GPG is installed.
Make sure GPG is installed.
