diff --git a/roles/nodejs/tasks/main.yml b/roles/nodejs/tasks/main.yml index 457720c9b..38faf45e2 100644 --- a/roles/nodejs/tasks/main.yml +++ b/roles/nodejs/tasks/main.yml @@ -1,22 +1,51 @@ -# 2019-01-16/29: duplicate Node.js code unified thanks to @jvonau. It's used by: -# roles/pbx/tasks/main.yml with roles/pbx/meta/main.yml (for Asterisk with FreePBX, forthcoming early in 2019, see PR #1405) +# 2019-02-03: SEE VAR nodejs_version: 10.x (FOR NOW!) IN vars/default_vars.yml +# AND IF NEC OVERRIDE THIS IN /etc/iiab/local_vars.yml + +# 2019-01-16: duplicate Node.js code originally unified by @jvonau. It's used by: # roles/nodered/tasks/main.yml with roles/nodered/meta/main.yml +# roles/pbx/tasks/main.yml with roles/pbx/meta/main.yml (for Asterisk with FreePBX, forthcoming early in 2019, see PR #1405) # roles/sugarizer/tasks/main.yml with roles/sugarizer/meta/main.yml -# WE SHOULD TEST FOR ANY VERSIONS OF Node.js THAT MIGHT ALREADY BE INSTALLED! -# IF THESE DO NOT MATCH {{ nodejs_version }} AS SET IN vars/defaults_vars.yml, -# IIAB SHOULD HALT WITH AN EXPLANATION: https://github.com/iiab/iiab/issues/1445 -# 2019-01-16: fyi Node.js 10.x became "LTS" on 2018-10-30 but distros are -# holding back for now: certainly Ubuntu 18.04 and even Debian 10/Buster -# ("testing" branch) both install Node.js 8.x (instead of 10.x). While the -# more bleeding-edge Debian Sid ("unstable" branch) does install Node.js 10.x -# -# This May Change: thanks all for running "apt -a list nodejs" on Buster's -# daily builds @ www.debian.org/devel/debian-installer/ and Disco Dingo (Ubuntu -# 19.04) https://launchpad.net/ubuntu/+source/nodejs to keep us informed! +# 1. TEST IF Node.js ALEADY INSTALLED & WARN AS NEC + +# 2019-02-03: BELOW TESTS IF 'nodejs' VERSION IS ALREADY INSTALLED: +# IF SO & THIS DOESN'T MATCH nodejs_version AS SET IN defaults_vars.yml +# AND/OR local_vars.yml IIAB HALTS WITH AN EXPLANATION (PR #1447) + +- name: Try to run 'nodejs -v' to get Node.js version + # 'node -v' doesn't work with older versions e.g. Ubuntu 16.04's nodejs 4.2.6 + # Both below convert v10.15.1 to 10.x, but this is safer: (removes non-digits) + shell: nodejs -v | sed 's/[^0-9]*//' | sed 's/[^0-9].*/.x/' + #shell: nodejs -v | sed 's/^[vV]//' | sed 's/\..*/.x/' + register: nodejs_version_installed + +#- debug: +# var: nodejs_version_installed + +# When nodejs is NOT installed: +# nodejs_version_installed.rc == 0 # Crazy with stderr below, "due to pipes" +# nodejs_version_installed.stdout == "" +# nodejs_version_installed.stderr == "/bin/sh: 1: nodejs: not found" +# BOTH ABOVE (incl non-null stderr) are USED BELOW to confirm install is nec! + +- name: "ENFORCE PRECONDITION: Stop installing (intentionally fail) IF an installed 'nodejs' version isn't {{ nodejs_version }}" + fail: + msg: > + PLEASE REMOVE 'nodejs' VERSION {{ nodejs_version_installed.stdout }} AS + IT DOES NOT MATCH THE REQUIRED nodejs_version: {{ nodejs_version }} -- + as set in /opt/iiab/iiab/vars/default_vars.yml and/or + /etc/iiab/local_vars.yml -- then re-run this IIAB installer. + when: nodejs_version_installed is defined and nodejs_version_installed.stdout != nodejs_version and nodejs_version_installed.stderr == "" + +- name: Warn if Node.js {{ nodejs_version}} already installed & might be updated + debug: + msg: "WARN: YOUR Node.js {{ nodejs_version }} MIGHT NOW BE UPDATED USING nodesource.com" + when: nodejs_version_installed is defined and nodejs_version_installed.stdout == nodejs_version + + +# 2. INSTALL Node.js USING nodesource.com -#- name: Set up Node.js {{ nodejs_version }} apt sources (debuntu distros UP TO 2017) - name: Set up Node.js {{ nodejs_version }} apt sources (debuntu) shell: curl -sL https://deb.nodesource.com/setup_{{ nodejs_version }} | bash - args: @@ -26,8 +55,7 @@ # NOT NEC TO TEST FOR is_raspbian_8 OR is_raspbian_9 AS /opt/iiab/iiab/vars/.yml # DEFINES THESE AS SUBSETS OF is_debian_8 OR is_debian_9 (FOR NOW!) -#- name: Install Node.js {{ nodejs_version }} which includes /usr/bin/npm (debuntu distros UP TO 2017) -- name: Install Node.js {{ nodejs_version }} which includes /usr/bin/npm (debuntu) +- name: Install latest Node.js {{ nodejs_version }} which includes /usr/bin/npm (debuntu) package: # name: nodejs={{ nodejs_version }} name: nodejs @@ -42,6 +70,7 @@ warn: no when: internet_available and is_redhat + # 2018-07-14: BOTH STEPS ABOVE TAKE TIME, but Raspbian (apt offers npm # 1.4.21) & Debian 9 (apt offers no npm!) STILL NEED the above # nodesource.com approach to get a version of npm that works with Sugarizer: @@ -53,7 +82,7 @@ # # BUT FOR NOW: Ubuntu 18.04's apt (approach below) brings in npm 3.5.2, # which appears suffic "SO FAR"? 18.04's nodejs 8.10.0 is more reassuring! - +# # CRAZY IDEA: most versions of npm can upgrade themselves to the latest # (6.2.0 for now) using command "npm install -g npm", if that helps us in # future, e.g. TK's memory issue etc? If so, be CAREFUL this puts npm @@ -61,6 +90,11 @@ # where it upgrades /usr/bin/npm in place: # https://askubuntu.com/questions/1036278/npm-is-incorrect-version-on-latest-ubuntu-18-04-installation +# 2019-02-03: OLD WAY (PRIOR TO 2019) BELOW. Since them, @m-anish helped +# us standardize on the above nodesource.com approach i.e. +# https://github.com/nodesource/distributions#debinstall ...across all +# distros (so nodejs & npm always findable in /usr/bin, for Node-RED etc) + # - name: Install packages nodejs {{ nodejs_version }} and npm (debuntu distros AFTER 2017, or other distros) # package: # name: @@ -68,3 +102,12 @@ # - npm # state: latest # when: internet_available and not (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17) + +# 2019-01-16: fyi Node.js 10.x became "LTS" on 2018-10-30 but distros are +# holding back for now: certainly Ubuntu 18.04 and even Debian 10/Buster +# ("testing" branch) both install Node.js 8.x (instead of 10.x). While the +# more bleeding-edge Debian Sid ("unstable" branch) does install Node.js 10.x +# +# This May Change: thanks all for running "apt -a list nodejs" on Buster's +# daily builds @ www.debian.org/devel/debian-installer/ and Disco Dingo (Ubuntu +# 19.04) https://launchpad.net/ubuntu/+source/nodejs to keep us informed!