From dccbd181ada338253c8445745464f00e5a87683b Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 12 Feb 2019 13:13:47 -0500 Subject: [PATCH 01/12] Update main.yml --- roles/nodejs/tasks/main.yml | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/roles/nodejs/tasks/main.yml b/roles/nodejs/tasks/main.yml index 0b6f15d4b..474b0287c 100644 --- a/roles/nodejs/tasks/main.yml +++ b/roles/nodejs/tasks/main.yml @@ -29,14 +29,20 @@ # 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: "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: ASK apt/yum/dnf TO REMOVE PRE-EXISTING Node.js {{ nodejs_version_installed.stdout }} (IF IT'S NOT {{ nodejs_version }}) + package: + name: nodejs + state: absent + when: nodejs_version_installed is defined and nodejs_version_installed.stdout != nodejs_version and nodejs_version_installed.stdout != "" - name: Warn if Node.js {{ nodejs_version}} already installed & might be updated debug: @@ -46,6 +52,13 @@ # 2. INSTALL Node.js USING nodesource.com +# SHOULD NOT BE NEC, AS STANZA BELOW SHOULD OVERWRITE /etc/apt/sources.list.d/nodesource.list REGARDLESS +#- name: Clear prior /etc/apt/sources.list.d/nodesource.list (permitting downgrade if nec) +# file: +# path: /etc/apt/sources.list.d/nodesource.list +# state: absent +# when: internet_available and is_debuntu + - name: Set up Node.js {{ nodejs_version }} apt sources (debuntu) shell: curl -sL https://deb.nodesource.com/setup_{{ nodejs_version }} | bash - args: From 3341453487aa4f82475cb15960c4bf1455c072b6 Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 12 Feb 2019 13:31:52 -0500 Subject: [PATCH 02/12] Update main.yml --- roles/nodejs/tasks/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/nodejs/tasks/main.yml b/roles/nodejs/tasks/main.yml index 474b0287c..3c6b075f2 100644 --- a/roles/nodejs/tasks/main.yml +++ b/roles/nodejs/tasks/main.yml @@ -38,6 +38,7 @@ # /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 == "" +# BRUTAL but ensures consistency across OS's / distros like Raspbian Desktop & Ubermix that often include an older version of Node.js - name: ASK apt/yum/dnf TO REMOVE PRE-EXISTING Node.js {{ nodejs_version_installed.stdout }} (IF IT'S NOT {{ nodejs_version }}) package: name: nodejs From 688427ddf5d03563dbfca0e66c7ef1c5ee9bd30f Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 12 Feb 2019 13:32:49 -0500 Subject: [PATCH 03/12] Update main.yml --- roles/nodered/tasks/main.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/roles/nodered/tasks/main.yml b/roles/nodered/tasks/main.yml index 1a8fc888e..7f3c8373d 100644 --- a/roles/nodered/tasks/main.yml +++ b/roles/nodered/tasks/main.yml @@ -1,6 +1,13 @@ # 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 +# BRUTAL but ensures consistency across OS's / distros like Raspbian Desktop & Ubermix that often include an older version of Node-RED +- name: ASK apt/yum/dnf TO REMOVE PRE-EXISTING Node-RED (IF IT WAS INSTALLED BY OS PKG MANAGER) + package: + name: nodered + state: absent + when: 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 From 786ccef90499b7db911a48a71ee7918f15dd40fd Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 12 Feb 2019 17:50:01 -0500 Subject: [PATCH 04/12] Update node-red.service.j2 --- roles/nodered/templates/node-red.service.j2 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/roles/nodered/templates/node-red.service.j2 b/roles/nodered/templates/node-red.service.j2 index d6c9df000..aa35f8d80 100644 --- a/roles/nodered/templates/node-red.service.j2 +++ b/roles/nodered/templates/node-red.service.j2 @@ -5,10 +5,12 @@ After=syslog.target network.target [Service] # Ansible template HAD: if is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17 # Ansible template HAD: if is_debuntu +{% if is_rpi %} ExecStart=/usr/bin/node-red-pi --max-old-space-size=128 -v -# Ansible template HAD: else +{% else %} # ExecStart=/usr/local/bin/node-red-pi --max-old-space-size=128 -v -# Ansible template HAD: endif +ExecStart=/usr/bin/node-red-pi -v +{% endif %} Restart=on-failure KillSignal=SIGINT From b0b37f8a3b804b33a8019e198ffc5a139c062e34 Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 12 Feb 2019 18:14:01 -0500 Subject: [PATCH 05/12] only npm install those (of 3) pkgs needed e.g. by Raspbian Desktop --- roles/nodered/tasks/main.yml | 54 ++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/roles/nodered/tasks/main.yml b/roles/nodered/tasks/main.yml index 7f3c8373d..9e282d298 100644 --- a/roles/nodered/tasks/main.yml +++ b/roles/nodered/tasks/main.yml @@ -1,15 +1,53 @@ # 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 -# BRUTAL but ensures consistency across OS's / distros like Raspbian Desktop & Ubermix that often include an older version of Node-RED -- name: ASK apt/yum/dnf TO REMOVE PRE-EXISTING Node-RED (IF IT WAS INSTALLED BY OS PKG MANAGER) - package: - name: nodered - state: absent +# Too brutal, as this removed customizations on graphical desktop OS's e.g. +# Raspbian Desktop's: +# 1. Node-RED's icon (Raspberry Menu in top-left -> Programming -> Node-RED) +# 2. scripts like {node-red-start, node-red-stop, node-red-log} in /usr/bin +# 3. other changes per /usr/bin/update-nodejs-and-nodered summarized at +# https://nodered.org/docs/hardware/raspberrypi for example low-memory +# flag --max_old_space_size=256 for unit file (any reason we use 128?) +## BRUTAL but ensures consistency across OS's / distros like Raspbian Desktop & Ubermix that often include an older version of Node-RED +#- name: ASK apt/yum/dnf TO REMOVE PRE-EXISTING Node-RED (IF IT WAS INSTALLED BY OS PKG MANAGER) +# package: +# name: nodered +# state: absent +# when: 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 + +# To protect pre-installed packages within /usr/lib/node_modules in graphical +# desktop OS's like Raspbian Desktop & Ubermix, we now only install those that +# are missing -- among the 3 below. WARNING: THIS COULD POTENTIALLY LEAD TO +# INCOMPATIBILITIES, IF OS'S /usr/lib/node_modules/node-red GETS OUT OF DATE! + +# /usr/lib/node_modules/node-red is PRE-INSTALLED by Raspbian Desktop, even if +# their package (42MB, 0.19.4) is a bit out of date compared to npm's (55MB, +# 0.19.5) as of 2019-02-12. Among others in /usr/lib/node_modules, pre-placed +# by Raspbian Desktop's apt package 'nodered': +# node-red-contrib-ibm-watson-iot, node-red-contrib-play-audio, +# node-red-node-ledborg, node-red-node-ping, node-red-node-pi-sense-hat +# node-red-node-random, node-red-node-serialport, node-red-node-smooth +- name: Globally 'npm install' pkg 'node-red' if /usr/lib/node_modules/node-red missing (most OS's except for Raspbian Desktop) + command: npm install -g --unsafe-perm node-red + creates: /usr/lib/node_modules/node-red when: 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 +# NOT pre-installed by Raspbian Desktop as of 2019-02-12...so we install this +# on most all OS's: +- name: Globally 'npm install' pkg 'node-red-admin' if /usr/lib/node_modules/node-red-admin missing (most OS's) + command: npm install -g --unsafe-perm node-red-admin + creates: /usr/lib/node_modules/node-red-admin + when: nodered_install + +# NOT pre-installed by Raspbian Desktop as of 2019-02-12...so we install this +# on most all OS's: +- name: Globally 'npm install' pkg 'node-red-dashboard' if /usr/lib/node_modules/node-red-dashboard missing (most OS's) + command: npm install -g --unsafe-perm node-red-dashboard + creates: /usr/lib/node_modules/node-red-dashboard when: nodered_install - name: Ensure Linux group 'nodered' exists @@ -117,7 +155,7 @@ - option: name value: Node-RED - option: description - value: '"Node-RED is a flow-based development tool for visual programming developed originally by IBM for wiring together hardware devices, APIs and online services as part of the Internet of Things. Node-RED provides a web browser-based flow editor, which can be used to create JavaScript functions."' + value: '"Node-RED is a flow-based development tool for visual programming developed originally by IBM for wiring together hardware devices, APIs and online services as part of the Internet of Things. Node-RED provides a web browser-based flow editor, which can be used to create JavaScript functions."' - option: nodered_install value: "{{ nodered_install }}" - option: nodered_enabled From 96f89a2a4a12b76a4b2c66a695b0f5ecf9e512dc Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 12 Feb 2019 18:23:31 -0500 Subject: [PATCH 06/12] Update main.yml --- roles/nodered/tasks/main.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/roles/nodered/tasks/main.yml b/roles/nodered/tasks/main.yml index 9e282d298..f02b618a9 100644 --- a/roles/nodered/tasks/main.yml +++ b/roles/nodered/tasks/main.yml @@ -33,21 +33,24 @@ # node-red-node-random, node-red-node-serialport, node-red-node-smooth - name: Globally 'npm install' pkg 'node-red' if /usr/lib/node_modules/node-red missing (most OS's except for Raspbian Desktop) command: npm install -g --unsafe-perm node-red - creates: /usr/lib/node_modules/node-red + args: + creates: /usr/lib/node_modules/node-red when: nodered_install # NOT pre-installed by Raspbian Desktop as of 2019-02-12...so we install this # on most all OS's: - name: Globally 'npm install' pkg 'node-red-admin' if /usr/lib/node_modules/node-red-admin missing (most OS's) command: npm install -g --unsafe-perm node-red-admin - creates: /usr/lib/node_modules/node-red-admin + args: + creates: /usr/lib/node_modules/node-red-admin when: nodered_install # NOT pre-installed by Raspbian Desktop as of 2019-02-12...so we install this # on most all OS's: - name: Globally 'npm install' pkg 'node-red-dashboard' if /usr/lib/node_modules/node-red-dashboard missing (most OS's) command: npm install -g --unsafe-perm node-red-dashboard - creates: /usr/lib/node_modules/node-red-dashboard + args: + creates: /usr/lib/node_modules/node-red-dashboard when: nodered_install - name: Ensure Linux group 'nodered' exists From c777f8be2f7dda530dcbd4656addaa5adaa272ab Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 12 Feb 2019 19:12:44 -0500 Subject: [PATCH 07/12] Update main.yml --- roles/nodejs/tasks/main.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/roles/nodejs/tasks/main.yml b/roles/nodejs/tasks/main.yml index 3c6b075f2..bc2793c92 100644 --- a/roles/nodejs/tasks/main.yml +++ b/roles/nodejs/tasks/main.yml @@ -53,8 +53,10 @@ # 2. INSTALL Node.js USING nodesource.com -# SHOULD NOT BE NEC, AS STANZA BELOW SHOULD OVERWRITE /etc/apt/sources.list.d/nodesource.list REGARDLESS -#- name: Clear prior /etc/apt/sources.list.d/nodesource.list (permitting downgrade if nec) +# 2019-02-12: Should not be nec, as stanza below it should overwrite +# /etc/apt/sources.list.d/nodesource.list regardless! +# +#- name: Clear prior /etc/apt/sources.list.d/nodesource.list (permitting Node.js downgrade if nec) # file: # path: /etc/apt/sources.list.d/nodesource.list # state: absent From e519410e4cd9b3ccbe64509f2a2bbdb86a90bb19 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Feb 2019 01:02:04 -0500 Subject: [PATCH 08/12] Update and rename node-red.service.j2 to nodered.service.j2 --- .../templates/{node-red.service.j2 => nodered.service.j2} | 6 ++++++ 1 file changed, 6 insertions(+) rename roles/nodered/templates/{node-red.service.j2 => nodered.service.j2} (88%) diff --git a/roles/nodered/templates/node-red.service.j2 b/roles/nodered/templates/nodered.service.j2 similarity index 88% rename from roles/nodered/templates/node-red.service.j2 rename to roles/nodered/templates/nodered.service.j2 index aa35f8d80..547062ee5 100644 --- a/roles/nodered/templates/node-red.service.j2 +++ b/roles/nodered/templates/nodered.service.j2 @@ -19,9 +19,15 @@ SyslogIdentifier=node-red StandardOutput=syslog # non-root user to run as +{% if is_rpi %} +WorkingDirectory=/home/pi/ +User=pi +Group=pi +{% else %} WorkingDirectory=/home/nodered/ User=nodered Group=nodered +{% endif %} [Install] WantedBy=multi-user.target From 4b1d53aa62fd7ab7f11953b336185e70839f8ffe Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Feb 2019 01:04:37 -0500 Subject: [PATCH 09/12] Update main.yml --- roles/nodered/tasks/main.yml | 178 +++++++++++++++++++++++------------ 1 file changed, 119 insertions(+), 59 deletions(-) diff --git a/roles/nodered/tasks/main.yml b/roles/nodered/tasks/main.yml index f02b618a9..9e7cb10f0 100644 --- a/roles/nodered/tasks/main.yml +++ b/roles/nodered/tasks/main.yml @@ -1,80 +1,138 @@ # 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 -# Too brutal, as this removed customizations on graphical desktop OS's e.g. -# Raspbian Desktop's: +# BRUTAL but ensures consistency across OS's / distros like Raspbian Desktop & +# Ubermix that often include an older version of Node-RED. Brutal, as this +# removes customizations on graphical desktop OS's e.g. Raspbian Desktop's: # 1. Node-RED's icon (Raspberry Menu in top-left -> Programming -> Node-RED) # 2. scripts like {node-red-start, node-red-stop, node-red-log} in /usr/bin # 3. other changes per /usr/bin/update-nodejs-and-nodered summarized at # https://nodered.org/docs/hardware/raspberrypi for example low-memory -# flag --max_old_space_size=256 for unit file (any reason we use 128?) -## BRUTAL but ensures consistency across OS's / distros like Raspbian Desktop & Ubermix that often include an older version of Node-RED -#- name: ASK apt/yum/dnf TO REMOVE PRE-EXISTING Node-RED (IF IT WAS INSTALLED BY OS PKG MANAGER) -# package: -# name: nodered -# state: absent -# when: 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 - -# To protect pre-installed packages within /usr/lib/node_modules in graphical -# desktop OS's like Raspbian Desktop & Ubermix, we now only install those that -# are missing -- among the 3 below. WARNING: THIS COULD POTENTIALLY LEAD TO -# INCOMPATIBILITIES, IF OS'S /usr/lib/node_modules/node-red GETS OUT OF DATE! - -# /usr/lib/node_modules/node-red is PRE-INSTALLED by Raspbian Desktop, even if -# their package (42MB, 0.19.4) is a bit out of date compared to npm's (55MB, -# 0.19.5) as of 2019-02-12. Among others in /usr/lib/node_modules, pre-placed -# by Raspbian Desktop's apt package 'nodered': -# node-red-contrib-ibm-watson-iot, node-red-contrib-play-audio, -# node-red-node-ledborg, node-red-node-ping, node-red-node-pi-sense-hat -# node-red-node-random, node-red-node-serialport, node-red-node-smooth -- name: Globally 'npm install' pkg 'node-red' if /usr/lib/node_modules/node-red missing (most OS's except for Raspbian Desktop) - command: npm install -g --unsafe-perm node-red - args: - creates: /usr/lib/node_modules/node-red +# flag --max_old_space_size=256 for unit file (we're using 128 on RPi) +# That we'll reconstitute below! +- name: ASK apt/yum/dnf TO REMOVE PRE-EXISTING 'nodered' (IF PREVIOUSLY INSTALLED BY OS PKG MANAGER) + package: + name: nodered + state: absent when: nodered_install -# NOT pre-installed by Raspbian Desktop as of 2019-02-12...so we install this -# on most all OS's: -- name: Globally 'npm install' pkg 'node-red-admin' if /usr/lib/node_modules/node-red-admin missing (most OS's) - command: npm install -g --unsafe-perm node-red-admin - args: - creates: /usr/lib/node_modules/node-red-admin - when: nodered_install +- name: "Globally 'npm install' 3 Node-RED packages: node-red, node-red-admin, node-red-dashboard" + command: npm install -g --unsafe-perm node-red node-red-admin node-red-dashboard + when: nodered_install and internet_available -# NOT pre-installed by Raspbian Desktop as of 2019-02-12...so we install this -# on most all OS's: -- name: Globally 'npm install' pkg 'node-red-dashboard' if /usr/lib/node_modules/node-red-dashboard missing (most OS's) - command: npm install -g --unsafe-perm node-red-dashboard - args: - creates: /usr/lib/node_modules/node-red-dashboard - when: nodered_install +- name: "Globally 'npm install' 8 Node-RED learning examples for RPi: node-red-contrib-ibm-watson-iot, node-red-contrib-play-audio, node-red-node-ledborg, node-red-node-ping, node-red-node-pi-sense-hat, node-red-node-random, node-red-node-serialport, node-red-node-smooth" + command: npm install -g --unsafe-perm node-red-contrib-ibm-watson-iot node-red-contrib-play-audio node-red-node-ledborg node-red-node-ping node-red-node-pi-sense-hat node-red-node-random node-red-node-serialport node-red-node-smooth + when: nodered_install and internet_available and is_rpi -- name: Ensure Linux group 'nodered' exists +# TEST UNNEC ICON/MENU FILE PLACEMENT ON RASPIAN LITE TOO ! +- name: 'Download/Install 4 useful items for RPi: Node-RED icon, start menu item, /etc/logrotate.d/nodered, tweaked "Pi cpu temperature.json"' + get_url: + url: "{{ item.url }}" + dest: "{{ item.dest }}" + with_items: + - url: https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-icon.svg + dest: /usr/share/icons/hicolor/scalable/apps/node-red-icon.svg + - url: https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/Node-RED.desktop + dest: /usr/share/applications/Node-RED.desktop + - url: https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/nodered.rotate + dest: /etc/logrotate.d/nodered + - url: 'https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/Pi%20cpu%20temperature.json' + dest: '/usr/lib/node_modules/node-red-contrib-ibm-watson-iot/examples/Pi cpu temperature.json' + when: nodered_install and internet_available and is_rpi + +#- name: Replace/Tweak "node-red-contrib-ibm-watson-iot/examples/Pi cpu temperature.json" (rpi) +# command: 'curl -sL -o /usr/lib/node_modules/node-red-contrib-ibm-watson-iot/examples/Pi\ cpu\ temperature.json https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/Pi%20cpu%20temperature.json' +# when: nodered_install and internet_available and is_rpi + +- name: 'Download/Install 4 RPi executables to /usr/bin: node-red-start, node-red-stop, node-red-restart, node-red-log' + get_url: + url: "{{ item }}" + dest: /usr/bin + mode: a+x + with: + - https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start + - https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-stop + - https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-restart + - https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-log + when: nodered_install and internet_available and is_rpi + +## To protect pre-installed packages within /usr/lib/node_modules in graphical +## desktop OS's like Raspbian Desktop & Ubermix, we now only install those that +## are missing -- among the 3+8 below. WARNING: THIS COULD POTENTIALLY LEAD TO +## INCOMPATIBILITIES, IF OS'S /usr/lib/node_modules/node-red GETS OUT OF DATE! +# +## /usr/lib/node_modules/node-red is PRE-INSTALLED by Raspbian Desktop, even if +## their package (42MB, 0.19.4) is a bit out of date compared to npm's (55MB, +## 0.19.5) as of 2019-02-12. Among others in /usr/lib/node_modules, pre-placed +## by Raspbian Desktop's apt package 'nodered': +## node-red-contrib-ibm-watson-iot, node-red-contrib-play-audio, +## node-red-node-ledborg, node-red-node-ping, node-red-node-pi-sense-hat +## node-red-node-random, node-red-node-serialport, node-red-node-smooth +#- name: Globally 'npm install' pkg 'node-red' if /usr/lib/node_modules/node-red missing (most OS's except for Raspbian Desktop) +# #command: npm install -g --unsafe-perm node-red +# command: npm install -g --unsafe-perm node-red@latest +# args: +# creates: /usr/lib/node_modules/node-red +# when: nodered_install and internet_available +# +## NOT pre-installed by Raspbian Desktop as of 2019-02-12...so we install this +## on most all OS's: +#- name: Globally 'npm install' pkg 'node-red-admin' if /usr/lib/node_modules/node-red-admin missing (most OS's) +# command: npm install -g --unsafe-perm node-red-admin +# args: +# creates: /usr/lib/node_modules/node-red-admin +# when: nodered_install and internet_available +# +## NOT pre-installed by Raspbian Desktop as of 2019-02-12...so we install this +## on most all OS's: +#- name: Globally 'npm install' pkg 'node-red-dashboard' if /usr/lib/node_modules/node-red-dashboard missing (most OS's) +# command: npm install -g --unsafe-perm node-red-dashboard +# args: +# creates: /usr/lib/node_modules/node-red-dashboard +# when: nodered_install and internet_available + + +- name: Create /home/pi/.node-red/ directory (rpi) + file: + path: /home/pi/.node-red + state: directory + owner: pi + group: pi + mode: 0775 + when: nodered_install and is_rpi + +- name: Install /home/pi/.node-red/settings.js from template, with authentication (rpi) + template: + backup: yes + src: settings.js.j2 + dest: /home/pi/.node-red/settings.js + owner: pi + group: pi + mode: 0755 + when: nodered_install and is_rpi + +- name: Ensure Linux group 'nodered' exists (if not rpi) group: name: nodered state: present - when: nodered_install + when: nodered_install and not is_rpi -- name: Ensure Linux user 'nodered' exists and is added to group 'nodered' +- name: Ensure Linux user 'nodered' exists and is added to group 'nodered' (if not rpi) user: name: nodered group: nodered - when: nodered_install + when: nodered_install and not is_rpi -- name: Create /home/nodered/.node-red/ directory +- name: Ensure directory /home/nodered/.node-red/ exists (if not rpi) file: path: /home/nodered/.node-red state: directory owner: nodered group: nodered mode: 0775 - when: nodered_install + when: nodered_install and not is_rpi -- name: Install /home/nodered/.node-red/settings.js from template, with authentication +- name: Install /home/nodered/.node-red/settings.js from template, with authentication (if not rpi) template: backup: yes src: settings.js.j2 @@ -82,13 +140,14 @@ owner: nodered group: nodered mode: 0755 - when: nodered_install + when: nodered_install and not is_rpi -- name: Install /etc/systemd/system/node-red.service systemd unit file from template + +- name: Install /etc/systemd/system/nodered.service systemd unit file from template template: backup: yes - src: node-red.service.j2 - dest: /etc/systemd/system/node-red.service + src: nodered.service.j2 + dest: /etc/systemd/system/nodered.service owner: root group: root mode: 0666 @@ -132,22 +191,23 @@ state: restarted when: nodered_install -- name: Enable & (Re)start 'node-red' systemd service (if nodered_enabled) +- name: Enable & (Re)start 'nodered' systemd service (if nodered_enabled) systemd: daemon_reload: yes - name: node-red + name: nodered enabled: yes state: restarted when: nodered_enabled -- name: Disable & Stop 'node-red' systemd service (if not nodered_enabled) +- name: Disable & Stop 'nodered' systemd service (if not nodered_enabled) systemd: daemon_reload: yes - name: node-red + name: nodered enabled: no state: stopped when: not nodered_enabled + - name: Add 'nodered' variable values to {{ iiab_ini_file }} ini_file: path: "{{ iiab_ini_file }}" From eb418c37396205819859eddda3ecf4e1e4754c6e Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Feb 2019 01:25:36 -0500 Subject: [PATCH 10/12] Update main.yml --- roles/nodered/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/nodered/tasks/main.yml b/roles/nodered/tasks/main.yml index 9e7cb10f0..419989329 100644 --- a/roles/nodered/tasks/main.yml +++ b/roles/nodered/tasks/main.yml @@ -49,7 +49,7 @@ url: "{{ item }}" dest: /usr/bin mode: a+x - with: + with_items: - https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start - https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-stop - https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-restart From baad9d039eae154855c0ccb03fe66b9dbeb9f92a Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Feb 2019 01:36:12 -0500 Subject: [PATCH 11/12] Update main.yml --- roles/nodered/tasks/main.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/roles/nodered/tasks/main.yml b/roles/nodered/tasks/main.yml index 419989329..47adb0e66 100644 --- a/roles/nodered/tasks/main.yml +++ b/roles/nodered/tasks/main.yml @@ -16,6 +16,12 @@ state: absent when: nodered_install +# 2012-02-13: the 6 RPi stanzas below recreate Raspbian Desktop's Node-RED +# environment, inspired by: +# https://nodered.org/docs/hardware/raspberrypi +# https://github.com/node-red/raspbian-deb-package/blob/master/resources/update-nodejs-and-nodered +# https://github.com/iiab/iiab/pull/1497 + - name: "Globally 'npm install' 3 Node-RED packages: node-red, node-red-admin, node-red-dashboard" command: npm install -g --unsafe-perm node-red node-red-admin node-red-dashboard when: nodered_install and internet_available From 5752811121577d86e2a39c0a5679dee6b120d719 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Feb 2019 02:17:53 -0500 Subject: [PATCH 12/12] Update main.yml --- roles/nodered/defaults/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/nodered/defaults/main.yml b/roles/nodered/defaults/main.yml index 58b82a181..4862cbf5e 100644 --- a/roles/nodered/defaults/main.yml +++ b/roles/nodered/defaults/main.yml @@ -13,3 +13,4 @@ nodered_password_hash: $2b$08$oxgvoU9et3deSbXY8UNVTOWHSTQAyEASIal86RHVMqYQJhpPMN # To generate a new password hash, run 'node-red-admin hash-pw' and enter the # new password. Paste the resulting hash above. After Ansible runs, username # and password hash will be placed in: /home/nodered/.node-red/settings.js +# Or...on Raspberry Pi it's placed in: /home/pi/.node-red/settings.js