From 8f1afa2b6148fb54323b08707f2f7b80b8620932 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 16 Jan 2019 04:44:58 -0600 Subject: [PATCH 1/5] create nodejs as a shared role for sugarizer and nodered --- roles/nodejs/tasks/main.yml | 45 ++++++++++++++++++++++++++++++++ roles/nodered/meta/main.yml | 3 +++ roles/nodered/tasks/main.yml | 28 -------------------- roles/sugarizer/meta/main.yml | 1 + roles/sugarizer/tasks/main.yml | 47 +--------------------------------- 5 files changed, 50 insertions(+), 74 deletions(-) create mode 100644 roles/nodejs/tasks/main.yml create mode 100644 roles/nodered/meta/main.yml diff --git a/roles/nodejs/tasks/main.yml b/roles/nodejs/tasks/main.yml new file mode 100644 index 000000000..578f0ed2d --- /dev/null +++ b/roles/nodejs/tasks/main.yml @@ -0,0 +1,45 @@ +- name: Set up Node.js 8.x apt sources (debuntu distros up to 2017) + shell: curl -sL https://deb.nodesource.com/setup_8.x | bash - + args: + warn: no + when: internet_available and (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17) + # 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 latest Node.js which includes /usr/bin/npm (debuntu distros up to 2017) + package: + name: nodejs + # name: nodejs=8.x + state: latest + # state: present + when: internet_available and (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17) + +# 2019-01-15: BORROWED BY https://github.com/iiab/iiab/blob/master/roles/nodered/tasks/main.yml#L1-L26 + +# 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: +# https://github.com/iiab/iiab/issues/798#issuecomment-404324530 +# +# MORE POSITIVELY: this nodesource.com approach (brings in npm 5.6.0 with +# nodejs 8.11.3 for now, to any OS) would also work on Ubuntu 18.04, and +# might even bring about a sane consistency across mainline OS's? +# +# 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 +# in /usr/local/bin on Ubuntu 18.04 -- unlike Ubuntu 16.04 and Raspbian +# where it upgrades /usr/bin/npm in place: +# https://askubuntu.com/questions/1036278/npm-is-incorrect-version-on-latest-ubuntu-18-04-installation + +- name: Install latest packages nodejs and npm (debuntu distros after 2017, or other distros) + package: + name: + - nodejs + - npm + state: latest + when: internet_available and not (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17) + diff --git a/roles/nodered/meta/main.yml b/roles/nodered/meta/main.yml new file mode 100644 index 000000000..7848a81de --- /dev/null +++ b/roles/nodered/meta/main.yml @@ -0,0 +1,3 @@ + dependencies: + - { role: nodejs, tags: ['nodejs'], when: nodered_install } + diff --git a/roles/nodered/tasks/main.yml b/roles/nodered/tasks/main.yml index 840d69635..943672c5b 100644 --- a/roles/nodered/tasks/main.yml +++ b/roles/nodered/tasks/main.yml @@ -1,31 +1,3 @@ -- name: Set up Node.js 8.x apt sources (debuntu distros up to 2017) - shell: curl -sL https://deb.nodesource.com/setup_8.x | bash - - args: - warn: no - when: internet_available and (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17) and nodered_install - # 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 latest Node.js which includes /usr/bin/npm (debuntu distros up to 2017) - package: - name: nodejs - # name: nodejs=8.x - state: latest - # state: present - when: internet_available and (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17) and nodered_install - -# 2019-01-15: WE'RE BORROWING npm INSTALLATION TRICKS FROM MID-2018 SUGARIZER: -# https://github.com/iiab/iiab/blob/master/roles/sugarizer/tasks/main.yml#L77-L94 - -- name: Install latest packages nodejs and npm (debuntu distros after 2017, or other distros) - package: - name: - - nodejs - - npm - state: latest - when: internet_available and not (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17) and nodered_install - - - name: 'npm install node-red packages globally: node-red, node-red-admin, node-red-dashboard' shell: npm install -g --unsafe-perm node-red node-red-admin node-red-dashboard when: nodered_install diff --git a/roles/sugarizer/meta/main.yml b/roles/sugarizer/meta/main.yml index 1ac8adeed..33cae65ca 100644 --- a/roles/sugarizer/meta/main.yml +++ b/roles/sugarizer/meta/main.yml @@ -1,2 +1,3 @@ dependencies: - { role: mongodb, tags: ['generic','mongodb'], when: sugarizer_install } + - { role: nodejs, tags: ['nodejs'], when: sugarizer_install } diff --git a/roles/sugarizer/tasks/main.yml b/roles/sugarizer/tasks/main.yml index 7052d19c3..187bf364b 100644 --- a/roles/sugarizer/tasks/main.yml +++ b/roles/sugarizer/tasks/main.yml @@ -59,52 +59,7 @@ # 3. INSTALL A GOOD VERSION OF Node.js AND npm - -- name: Set up Node.js 8.x apt sources (debuntu distros up to 2017) - shell: curl -sL https://deb.nodesource.com/setup_8.x | bash - - args: - warn: no - when: internet_available and (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17) - # 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 latest Node.js which includes /usr/bin/npm (debuntu distros up to 2017) - package: - name: nodejs - # name: nodejs=8.x - state: latest - # state: present - when: internet_available and (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17) - -# 2019-01-15: BORROWED BY https://github.com/iiab/iiab/blob/master/roles/nodered/tasks/main.yml#L1-L26 - -# 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: -# https://github.com/iiab/iiab/issues/798#issuecomment-404324530 -# -# MORE POSITIVELY: this nodesource.com approach (brings in npm 5.6.0 with -# nodejs 8.11.3 for now, to any OS) would also work on Ubuntu 18.04, and -# might even bring about a sane consistency across mainline OS's? -# -# 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 -# in /usr/local/bin on Ubuntu 18.04 -- unlike Ubuntu 16.04 and Raspbian -# where it upgrades /usr/bin/npm in place: -# https://askubuntu.com/questions/1036278/npm-is-incorrect-version-on-latest-ubuntu-18-04-installation - -- name: Install latest packages nodejs and npm (debuntu distros after 2017, or other distros) - package: - name: - - nodejs - - npm - state: latest - when: internet_available and not (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17) - +# moved to nodejs # 4. RUN "npm install" TO POPULATE ~35MB /opt/iiab/sugarizer-server/node_modules From feaf152f049ed6fe68e9933409990c53b9722b30 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 16 Jan 2019 11:40:12 -0500 Subject: [PATCH 2/5] Update main.yml --- roles/nodejs/tasks/main.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/roles/nodejs/tasks/main.yml b/roles/nodejs/tasks/main.yml index 578f0ed2d..6658ad739 100644 --- a/roles/nodejs/tasks/main.yml +++ b/roles/nodejs/tasks/main.yml @@ -1,4 +1,16 @@ -- name: Set up Node.js 8.x apt sources (debuntu distros up to 2017) +# 2019-01-16: duplicate Node.js code unified thanks to @jvonau. It's used by: +# roles/sugarizer/tasks/main.yml with roles/sugarizer/meta/main.yml +# roles/nodered/tasks/main.yml with roles/nodered/meta/main.yml + +# 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/ to keep us informed! + +- name: Set up Node.js 8.x apt sources (debuntu distros UP TO 2017) shell: curl -sL https://deb.nodesource.com/setup_8.x | bash - args: warn: no @@ -6,7 +18,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 latest Node.js which includes /usr/bin/npm (debuntu distros up to 2017) +- name: Install latest Node.js which includes /usr/bin/npm (debuntu distros UP TO 2017) package: name: nodejs # name: nodejs=8.x @@ -14,8 +26,6 @@ # state: present when: internet_available and (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17) -# 2019-01-15: BORROWED BY https://github.com/iiab/iiab/blob/master/roles/nodered/tasks/main.yml#L1-L26 - # 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: @@ -35,11 +45,10 @@ # where it upgrades /usr/bin/npm in place: # https://askubuntu.com/questions/1036278/npm-is-incorrect-version-on-latest-ubuntu-18-04-installation -- name: Install latest packages nodejs and npm (debuntu distros after 2017, or other distros) +- name: Install latest packages nodejs and npm (debuntu distros AFTER 2017, or other distros) package: name: - nodejs - npm state: latest when: internet_available and not (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17) - From 2dc46766ed6c1b149f33acdc5e6a584d14b110ca Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 16 Jan 2019 11:41:46 -0500 Subject: [PATCH 3/5] Update main.yml --- roles/sugarizer/tasks/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/roles/sugarizer/tasks/main.yml b/roles/sugarizer/tasks/main.yml index 187bf364b..d9f0729c4 100644 --- a/roles/sugarizer/tasks/main.yml +++ b/roles/sugarizer/tasks/main.yml @@ -59,7 +59,9 @@ # 3. INSTALL A GOOD VERSION OF Node.js AND npm -# moved to nodejs + +# 2019-01-16: Moved to roles/nodejs/tasks/main.yml, thanks to roles/sugarizer/meta/main.yml + # 4. RUN "npm install" TO POPULATE ~35MB /opt/iiab/sugarizer-server/node_modules From 92da012d9e6a209264a79dd01a0eb4602c6183fc Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 16 Jan 2019 11:49:46 -0500 Subject: [PATCH 4/5] Update main.yml --- roles/sugarizer/tasks/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/sugarizer/tasks/main.yml b/roles/sugarizer/tasks/main.yml index d9f0729c4..c02197a4c 100644 --- a/roles/sugarizer/tasks/main.yml +++ b/roles/sugarizer/tasks/main.yml @@ -60,7 +60,8 @@ # 3. INSTALL A GOOD VERSION OF Node.js AND npm -# 2019-01-16: Moved to roles/nodejs/tasks/main.yml, thanks to roles/sugarizer/meta/main.yml +# 2019-01-16: @jvonau's PR #1403 moved installation of Node.js (8.x for now) & +# npm to roles/nodejs/tasks/main.yml, triggered by roles/sugarizer/meta/main.yml # 4. RUN "npm install" TO POPULATE ~35MB /opt/iiab/sugarizer-server/node_modules From d4eb254bde7b911a1be24160a37ff7393d9fe5f7 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 16 Jan 2019 11:50:09 -0500 Subject: [PATCH 5/5] Update main.yml --- roles/nodered/tasks/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/roles/nodered/tasks/main.yml b/roles/nodered/tasks/main.yml index 943672c5b..f51a23230 100644 --- a/roles/nodered/tasks/main.yml +++ b/roles/nodered/tasks/main.yml @@ -1,3 +1,6 @@ +# 2019-01-16: @jvonau's PR #1403 moved installation of Node.js (8.x for now) & +# npm to roles/nodejs/tasks/main.yml, triggered by roles/nodered/meta/main.yml + - name: 'npm install node-red packages globally: node-red, node-red-admin, node-red-dashboard' shell: npm install -g --unsafe-perm node-red node-red-admin node-red-dashboard when: nodered_install