Merge "install-nodejs: add support for RPM-based OSes"
This commit is contained in:
commit
06071290d1
@ -1,4 +1,13 @@
|
||||
Install NodeJS from nodesource
|
||||
Install NodeJS from nodesource.
|
||||
|
||||
**OS supported**
|
||||
|
||||
This role supports the following OS families:
|
||||
|
||||
- Debian
|
||||
- Fedora
|
||||
- Red Hat
|
||||
- SUSE
|
||||
|
||||
**Role Variables**
|
||||
|
||||
|
43
roles/install-nodejs/tasks/distros/install_Debian.yaml
Normal file
43
roles/install-nodejs/tasks/distros/install_Debian.yaml
Normal file
@ -0,0 +1,43 @@
|
||||
- name: Pin nodejs installs to nodesource
|
||||
copy:
|
||||
src: 00-nodesource.pref
|
||||
dest: /etc/apt/preferences.d/00-nodesource.pref
|
||||
become: yes
|
||||
|
||||
- name: Add nodesource repository key
|
||||
apt_key:
|
||||
url: "https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
|
||||
become: yes
|
||||
|
||||
- name: Add nodesource apt source repository
|
||||
apt_repository:
|
||||
repo: "deb-src https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main"
|
||||
state: present
|
||||
become: yes
|
||||
|
||||
- name: Add nodesource apt repository
|
||||
apt_repository:
|
||||
repo: "deb https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main"
|
||||
state: present
|
||||
update_cache: yes
|
||||
become: yes
|
||||
|
||||
# Use template so that we can easily update this in the future to be able to
|
||||
# use a mirror location.
|
||||
- name: Pin NodeJS to nodesource apt repository
|
||||
become: yes
|
||||
template:
|
||||
dest: /etc/apt/preferences.d/nodejs.pref
|
||||
group: root
|
||||
mode: 0644
|
||||
owner: root
|
||||
src: nodejs.pref.j2
|
||||
|
||||
- name: Install NodeJS from nodesource
|
||||
package:
|
||||
name: nodejs
|
||||
state: latest
|
||||
become: yes
|
||||
tags:
|
||||
# Ignore ANSIBLE0010: We really want latest version
|
||||
- skip_ansible_lint
|
32
roles/install-nodejs/tasks/distros/install_Fedora.yaml
Normal file
32
roles/install-nodejs/tasks/distros/install_Fedora.yaml
Normal file
@ -0,0 +1,32 @@
|
||||
- name: Install Nodesource repository (Fedora < 29)
|
||||
package:
|
||||
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"
|
||||
state: present
|
||||
when:
|
||||
- ansible_distribution_major_version < 29
|
||||
become: yes
|
||||
|
||||
- name: Fail installation if node version < 11 (Fedora >= 29)
|
||||
fail:
|
||||
msg: Fedora 29 and later only support NodeJS >= 11.x
|
||||
when:
|
||||
- ansible_distribution_major_version >= 29
|
||||
- node_version < 11
|
||||
|
||||
- name: Install Nodesource repository (Fedora >= 29)
|
||||
package:
|
||||
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"
|
||||
state: present
|
||||
when:
|
||||
- ansible_distribution_major_version >= 29
|
||||
- node_version >= 11
|
||||
become: yes
|
||||
|
||||
- name: Install NodeJS
|
||||
package:
|
||||
name: "nodejs"
|
||||
state: latest
|
||||
become: yes
|
||||
tags:
|
||||
# Ignore ANSIBLE0010: We really want latest version
|
||||
- skip_ansible_lint
|
18
roles/install-nodejs/tasks/distros/install_RedHat.yaml
Normal file
18
roles/install-nodejs/tasks/distros/install_RedHat.yaml
Normal file
@ -0,0 +1,18 @@
|
||||
- name: Install Nodesource repository
|
||||
package:
|
||||
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"
|
||||
state: present
|
||||
|
||||
- name: Update yum cache
|
||||
yum:
|
||||
update_cache: yes
|
||||
become: yes
|
||||
|
||||
- name: Install NodeJS
|
||||
package:
|
||||
name: "nodejs"
|
||||
state: latest
|
||||
become: yes
|
||||
tags:
|
||||
# Ignore ANSIBLE0010: We really want latest version
|
||||
- skip_ansible_lint
|
17
roles/install-nodejs/tasks/distros/install_Suse.yaml
Normal file
17
roles/install-nodejs/tasks/distros/install_Suse.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
- name: Update zypper cache
|
||||
zypper:
|
||||
update_cache: yes
|
||||
become: yes
|
||||
|
||||
- name: Set node package name
|
||||
set_fact:
|
||||
nodejs_pkg: "nodejs{{ node_version }}"
|
||||
|
||||
- name: Install NodeJS
|
||||
package:
|
||||
name: "{{ nodejs_pkg }}"
|
||||
state: latest
|
||||
become: yes
|
||||
tags:
|
||||
# Ignore ANSIBLE0010: We really want latest version
|
||||
- skip_ansible_lint
|
8
roles/install-nodejs/tasks/distros/install_default.yaml
Normal file
8
roles/install-nodejs/tasks/distros/install_default.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
# Note: there are possible workarounds:
|
||||
#
|
||||
# - https://github.com/nodejs/help/wiki/Installation#how-to-install-nodejs-via-binary-archive-on-linux
|
||||
# - https://github.com/nodejs/node/blob/master/BUILDING.md#building-nodejs-on-supported-platforms
|
||||
|
||||
- name: Fail for unsupported OSes
|
||||
fail:
|
||||
msg: "Unsupported OS family {{ ansible_os_family }}"
|
@ -1,57 +1,26 @@
|
||||
- name: Update apt cache
|
||||
apt:
|
||||
update_cache: yes
|
||||
become: yes
|
||||
- name: Check for the presence of node
|
||||
command: command -v node
|
||||
register: install_nodejs_node_installed
|
||||
ignore_errors: true
|
||||
|
||||
- name: Install prereqs
|
||||
package:
|
||||
name: apt-transport-https
|
||||
state: present
|
||||
become: yes
|
||||
- name: Check for the presence of npm
|
||||
command: command -v npm
|
||||
register: install_nodejs_npm_installed
|
||||
ignore_errors: true
|
||||
|
||||
- name: Pin nodejs installs to nodesource
|
||||
copy:
|
||||
src: 00-nodesource.pref
|
||||
dest: /etc/apt/preferences.d/00-nodesource.pref
|
||||
become: yes
|
||||
|
||||
- name: Add nodesource repository key
|
||||
apt_key:
|
||||
url: "https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
|
||||
become: yes
|
||||
|
||||
- name: Add nodesource apt source repository
|
||||
apt_repository:
|
||||
repo: "deb-src https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main"
|
||||
state: present
|
||||
become: yes
|
||||
|
||||
- name: Add nodesource apt repository
|
||||
apt_repository:
|
||||
repo: "deb https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main"
|
||||
state: present
|
||||
update_cache: yes
|
||||
become: yes
|
||||
|
||||
# Use template so that we can easily update this in the future to be able to
|
||||
# use a mirror location.
|
||||
- name: Pin NodeJS to nodesource apt repository
|
||||
become: yes
|
||||
template:
|
||||
dest: /etc/apt/preferences.d/nodejs.pref
|
||||
group: root
|
||||
mode: 0644
|
||||
owner: root
|
||||
src: nodejs.pref.j2
|
||||
|
||||
- name: Install NodeJS from nodesource
|
||||
package:
|
||||
name: nodejs
|
||||
state: latest
|
||||
become: yes
|
||||
tags:
|
||||
# Ignore ANSIBLE0010: We really want latest version
|
||||
- skip_ansible_lint
|
||||
- name: Install nodejs according to distro
|
||||
include_tasks: "{{ lookup('first_found', params) }}"
|
||||
vars:
|
||||
params:
|
||||
files:
|
||||
- "install_{{ ansible_distribution }}.{{ ansible_distribution_major_version }}.yaml"
|
||||
- "install_{{ ansible_distribution }}.yaml"
|
||||
- "install_{{ ansible_os_family }}.yaml"
|
||||
- "install_default.yaml"
|
||||
paths:
|
||||
- distros
|
||||
when:
|
||||
install_nodejs_node_installed.rc == 1 or install_nodejs_npm_installed == 1
|
||||
|
||||
- name: Output node version
|
||||
command: node --version
|
||||
|
Loading…
Reference in New Issue
Block a user