Browse Source

install-nodejs: add support for RPM-based OSes

Change-Id: I437e2dbbe343335c978f43df1238d663067d6904
changes/49/631049/14
mhuin 7 months ago
parent
commit
102374feb4

+ 10
- 1
roles/install-nodejs/README.rst View File

@@ -1,4 +1,13 @@
1
-Install NodeJS from nodesource
1
+Install NodeJS from nodesource.
2
+
3
+**OS supported**
4
+
5
+This role supports the following OS families:
6
+
7
+- Debian
8
+- Fedora
9
+- Red Hat
10
+- SUSE
2 11
 
3 12
 **Role Variables**
4 13
 

+ 43
- 0
roles/install-nodejs/tasks/distros/install_Debian.yaml View File

@@ -0,0 +1,43 @@
1
+- name: Pin nodejs installs to nodesource
2
+  copy:
3
+    src: 00-nodesource.pref
4
+    dest: /etc/apt/preferences.d/00-nodesource.pref
5
+  become: yes
6
+
7
+- name: Add nodesource repository key
8
+  apt_key:
9
+    url: "https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
10
+  become: yes
11
+
12
+- name: Add nodesource apt source repository
13
+  apt_repository:
14
+    repo: "deb-src https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main"
15
+    state: present
16
+  become: yes
17
+
18
+- name: Add nodesource apt repository
19
+  apt_repository:
20
+    repo: "deb https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main"
21
+    state: present
22
+    update_cache: yes
23
+  become: yes
24
+
25
+# Use template so that we can easily update this in the future to be able to
26
+# use a mirror location.
27
+- name: Pin NodeJS to nodesource apt repository
28
+  become: yes
29
+  template:
30
+    dest: /etc/apt/preferences.d/nodejs.pref
31
+    group: root
32
+    mode: 0644
33
+    owner: root
34
+    src: nodejs.pref.j2
35
+
36
+- name: Install NodeJS from nodesource
37
+  package:
38
+    name: nodejs
39
+    state: latest
40
+  become: yes
41
+  tags:
42
+    # Ignore ANSIBLE0010: We really want latest version
43
+    - skip_ansible_lint

+ 32
- 0
roles/install-nodejs/tasks/distros/install_Fedora.yaml View File

@@ -0,0 +1,32 @@
1
+- name: Install Nodesource repository (Fedora < 29)
2
+  package:
3
+    name: "https://rpm.nodesource.com/pub_{{ node_version }}.x/fc/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/nodesource-release-fc{{ ansible_distribution_major_version }}-1.noarch.rpm"
4
+    state: present
5
+  when:
6
+    - ansible_distribution_major_version < 29
7
+  become: yes
8
+
9
+- name: Fail installation if node version < 11 (Fedora >= 29)
10
+  fail:
11
+    msg: Fedora 29 and later only support NodeJS >= 11.x
12
+  when:
13
+    - ansible_distribution_major_version >= 29
14
+    - node_version < 11
15
+
16
+- name: Install Nodesource repository (Fedora >= 29)
17
+  package:
18
+    name: "https://rpm.nodesource.com/pub_{{ node_version }}.x/fc/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/nodesource-release-fc{{ ansible_distribution_major_version }}-1.noarch.rpm"
19
+    state: present
20
+  when:
21
+    - ansible_distribution_major_version >= 29
22
+    - node_version >= 11
23
+  become: yes
24
+
25
+- name: Install NodeJS
26
+  package:
27
+    name: "nodejs"
28
+    state: latest
29
+  become: yes
30
+  tags:
31
+    # Ignore ANSIBLE0010: We really want latest version
32
+    - skip_ansible_lint

+ 18
- 0
roles/install-nodejs/tasks/distros/install_RedHat.yaml View File

@@ -0,0 +1,18 @@
1
+- name: Install Nodesource repository
2
+  package:
3
+    name: "https://rpm.nodesource.com/pub_{{ node_version }}.x/el/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/nodesource-release-el{{ ansible_distribution_major_version }}-1.noarch.rpm"
4
+    state: present
5
+
6
+- name: Update yum cache
7
+  yum:
8
+    update_cache: yes
9
+  become: yes
10
+
11
+- name: Install NodeJS
12
+  package:
13
+    name: "nodejs"
14
+    state: latest
15
+  become: yes
16
+  tags:
17
+    # Ignore ANSIBLE0010: We really want latest version
18
+    - skip_ansible_lint

+ 17
- 0
roles/install-nodejs/tasks/distros/install_Suse.yaml View File

@@ -0,0 +1,17 @@
1
+- name: Update zypper cache
2
+  zypper:
3
+    update_cache: yes
4
+  become: yes
5
+
6
+- name: Set node package name
7
+  set_fact:
8
+    nodejs_pkg: "nodejs{{ node_version }}"
9
+
10
+- name: Install NodeJS
11
+  package:
12
+    name: "{{ nodejs_pkg }}"
13
+    state: latest
14
+  become: yes
15
+  tags:
16
+    # Ignore ANSIBLE0010: We really want latest version
17
+    - skip_ansible_lint

+ 8
- 0
roles/install-nodejs/tasks/distros/install_default.yaml View File

@@ -0,0 +1,8 @@
1
+# Note: there are possible workarounds:
2
+#
3
+# - https://github.com/nodejs/help/wiki/Installation#how-to-install-nodejs-via-binary-archive-on-linux
4
+# - https://github.com/nodejs/node/blob/master/BUILDING.md#building-nodejs-on-supported-platforms
5
+
6
+- name: Fail for unsupported OSes
7
+  fail:
8
+    msg: "Unsupported OS family {{ ansible_os_family }}"

+ 23
- 54
roles/install-nodejs/tasks/main.yaml View File

@@ -1,57 +1,26 @@
1
-- name: Update apt cache
2
-  apt:
3
-    update_cache: yes
4
-  become: yes
5
-
6
-- name: Install prereqs
7
-  package:
8
-    name: apt-transport-https
9
-    state: present
10
-  become: yes
11
-
12
-- name: Pin nodejs installs to nodesource
13
-  copy:
14
-    src: 00-nodesource.pref
15
-    dest: /etc/apt/preferences.d/00-nodesource.pref
16
-  become: yes
17
-
18
-- name: Add nodesource repository key
19
-  apt_key:
20
-    url: "https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
21
-  become: yes
22
-
23
-- name: Add nodesource apt source repository
24
-  apt_repository:
25
-    repo: "deb-src https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main"
26
-    state: present
27
-  become: yes
28
-
29
-- name: Add nodesource apt repository
30
-  apt_repository:
31
-    repo: "deb https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main"
32
-    state: present
33
-    update_cache: yes
34
-  become: yes
35
-
36
-# Use template so that we can easily update this in the future to be able to
37
-# use a mirror location.
38
-- name: Pin NodeJS to nodesource apt repository
39
-  become: yes
40
-  template:
41
-    dest: /etc/apt/preferences.d/nodejs.pref
42
-    group: root
43
-    mode: 0644
44
-    owner: root
45
-    src: nodejs.pref.j2
46
-
47
-- name: Install NodeJS from nodesource
48
-  package:
49
-    name: nodejs
50
-    state: latest
51
-  become: yes
52
-  tags:
53
-    # Ignore ANSIBLE0010: We really want latest version
54
-    - skip_ansible_lint
1
+- name: Check for the presence of node
2
+  command: command -v node
3
+  register: install_nodejs_node_installed
4
+  ignore_errors: true
5
+
6
+- name: Check for the presence of npm
7
+  command: command -v npm
8
+  register: install_nodejs_npm_installed
9
+  ignore_errors: true
10
+
11
+- name: Install nodejs according to distro
12
+  include_tasks: "{{ lookup('first_found', params) }}"
13
+  vars:
14
+    params:
15
+      files:
16
+        - "install_{{ ansible_distribution }}.{{ ansible_distribution_major_version }}.yaml"
17
+        - "install_{{ ansible_distribution }}.yaml"
18
+        - "install_{{ ansible_os_family }}.yaml"
19
+        - "install_default.yaml"
20
+      paths:
21
+        - distros
22
+  when:
23
+    install_nodejs_node_installed.rc == 1 or install_nodejs_npm_installed == 1
55 24
 
56 25
 - name: Output node version
57 26
   command: node --version

Loading…
Cancel
Save