From: Matthew Watkins Date: Mon, 7 Nov 2022 10:41:21 +0000 (+0000) Subject: Feat: Add NodeSource NodeJS repository/package X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=509a860cdf1d33b3c3030c8e7cb6adcdd7eb1278;p=ansible%2Froles%2Flf-recommended-tools.git Feat: Add NodeSource NodeJS repository/package Issue-ID: RELENG-4482 Signed-off-by: Matthew Watkins Change-Id: I0187f5a57b63972452a715634ddfa6617615b2b7 --- diff --git a/tasks/main.yml b/tasks/main.yml index 3845bd1..1041a97 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -58,3 +58,82 @@ dest: /usr/local/bin/plantuml mode: 0755 become: true + +- name: Add NodeSource repository/NodeJS + vars: + # Sets the packaged/baseline version of NodeJS + nodejs_version: "16.x" + block: + - name: Add NodeSource repository/NodeJS under RedHat/CentOS + when: ansible_facts['os_family'] == 'RedHat' + block: + - name: Set up the Nodesource RPM directory. + set_fact: + nodejs_rhel_rpm_dir: "pub_{{ nodejs_version }}" + + - name: Import Nodesource RPM key + rpm_key: + key: + https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL + state: present + + - name: Add Nodesource repositories for Node.js (CentOS 7+). + yum: + name: + "https://rpm.nodesource.com/{{ nodejs_rhel_rpm_dir }}/el/\ + {{ ansible_distribution_major_version }}/\ + {{ ansible_architecture }}/nodesource-release-el\ + {{ ansible_distribution_major_version }}-1.noarch.rpm" + state: present + when: ansible_distribution_major_version | int >= 7 + register: node_repo + + - name: Update package cache if repo was added. + yum: update_cache=yes + when: node_repo is changed + tags: ["skip_ansible_lint"] + + - name: Ensure Node.js AppStream module is disabled (CentOS 8+). + command: yum module disable -y nodejs + args: + warn: false + register: module_disable + changed_when: "'Nothing to do.' not in module_disable.stdout" + when: ansible_distribution_major_version | int >= 8 + + - name: Ensure Node.js and npm are installed. + yum: + name: "nodejs-{{ nodejs_version | regex_replace('x', '') }}*" + state: present + become: true + + - name: Add NodeSource repository/NodeJS under Ubuntu + when: ansible_facts['distribution'] == 'Ubuntu' + block: + - 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_{{ nodejs_version }} \ + {{ ansible_distribution_release }} main" + state: present + + - name: Add NodeSource deb-src repository + apt_repository: + repo: "deb-src \ + https://deb.nodesource.com/node_{{ nodejs_version }} \ + {{ ansible_distribution_release }} main" + state: present + + - name: Install Node.js + apt: + pkg: + - nodejs + state: present + update_cache: true + become: true