Feat: Add NodeSource NodeJS repository/package 69/70969/10
authorMatthew Watkins <mwatkins@linuxfoundation.org>
Mon, 7 Nov 2022 10:41:21 +0000 (10:41 +0000)
committerMatthew Watkins <mwatkins@linuxfoundation.org>
Wed, 16 Nov 2022 23:11:44 +0000 (15:11 -0800)
Issue-ID: RELENG-4482
Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
Change-Id: I0187f5a57b63972452a715634ddfa6617615b2b7

tasks/main.yml

index 3845bd1..1041a97 100644 (file)
         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