1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-13 11:42:08 +00:00
iiab/roles/nodered/tasks/install.yml

150 lines
7.8 KiB
YAML
Raw Normal View History

2021-07-06 04:36:15 +00:00
# 2019-01-16: @jvonau's PR #1403 moved installation of Node.js [8.x at the time]
# and npm to roles/nodejs/tasks/main.yml
2020-01-05 03:53:16 +00:00
- name: "Set 'nodejs_install: True' and 'nodejs_enabled: True'"
set_fact:
nodejs_install: True
nodejs_enabled: True
# 2020-01-04 no longer triggered by roles/nodered/meta/main.yml
- name: NODEJS - run 'nodejs' role (attempt to install & enable Node.js)
2020-01-05 03:53:16 +00:00
include_role:
name: nodejs
- name: FAIL (STOP THE INSTALL) IF 'nodejs_installed is undefined'
fail:
msg: "Node-RED install cannot proceed, as Node.js is not installed."
when: nodejs_installed is undefined
# 2020-10-29: not really nec as Node-RED supports recent Node.js versions
#- name: FAIL (STOP THE INSTALL) IF 'nodejs_version != "12.x"'
# fail:
# msg: "Node-RED install cannot proceed, as it currently requires Node.js 12.x, whereas nodejs_version is set to {{ nodejs_version }}. Please check the value of nodejs_version in /opt/iiab/iiab/vars/default_vars.yml, /etc/iiab/local_vars.yml, /opt/iiab/iiab/roles/nodejs, etc."
# when: nodejs_version != "12.x"
2019-09-15 00:41:58 +00:00
# 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 (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
2021-07-06 04:36:15 +00:00
# 2019-02-13: the 6 RPi stanzas below recreate Raspbian Desktop's Node-RED
2019-09-15 00:41:58 +00:00
# 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
# https://nodered.org/docs/user-guide/node-red-admin built in since Node-RED
# 1.1.0 (2020-06-30). Run it using: node-red admin
# If you install it separately, run: node-red-admin
#
#- name: "Globally 'npm install' 3 Node-RED packages: node-red, node-red-admin, node-red-dashboard"
- name: "Globally 'npm install' 2 Node-RED packages: node-red, node-red-dashboard"
#command: npm install -g --unsafe-perm node-red node-red-admin node-red-dashboard
command: npm install -g --unsafe-perm node-red@latest node-red-dashboard@latest
# Above "@latest" recommended by https://nodered.org/docs/hardware/raspberrypi back in 2019
# 2022-06-08: New list copied from $EXTRANODES in https://github.com/node-red/linux-installers/blob/master/deb/update-nodejs-and-nodered
- name: "Globally 'npm install' 6 Node-RED learning examples IF Raspberry Pi hardware detected: node-red-node-pi-gpio, node-red-node-random, node-red-node-ping, node-red-contrib-play-audio, node-red-node-smooth, node-red-node-serialport"
#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
command: npm install -g --unsafe-perm node-red-node-pi-gpio@latest node-red-node-random@latest node-red-node-ping@latest node-red-contrib-play-audio@latest node-red-node-smooth@latest node-red-node-serialport@latest
#command: npm i --unsafe-perm --save --no-progress --no-update-notifier --no-audit --no-fund node-red-node-pi-gpio@latest node-red-node-random@latest node-red-node-ping@latest node-red-contrib-play-audio@latest node-red-node-smooth@latest node-red-node-serialport@latest 2>&1
when: rpi_model != "none"
2019-09-15 00:41:58 +00:00
## 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
- include_tasks: settings.yml
#when: not is_raspbian
2019-09-15 00:41:58 +00:00
- include_tasks: os-integration.yml
#- include_tasks: rpi_desk.yml
# when: is_raspbian
2019-09-15 00:41:58 +00:00
# 2022-06-08 OFFICIALLY RECOMMENDED /lib/systemd/system/nodered.service IS:
# https://github.com/node-red/linux-installers/blob/master/resources/nodered.service
# EXPLAINED AT https://nodered.org/docs/faq/customising-systemd-on-pi
#
# AS RECOMMENDED BY OFFICIAL INSTALLER SCRIPT:
# https://github.com/node-red/linux-installers/blob/master/deb/update-nodejs-and-nodered
# OFFICIAL INSTRUCTIONS: https://nodered.org/docs/getting-started/local
# https://nodered.org/docs/getting-started/raspberrypi
#
# Should /lib be considered instead of /etc ?
# - name: Install /etc/systemd/system/nodered.service systemd unit file from template
# template:
# src: nodered.service.j2
# dest: /etc/systemd/system/nodered.service
- name: Start by downloading https://github.com/node-red/linux-installers/blob/master/resources/nodered.service to /etc/systemd/system/nodered.service
get_url:
url: https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.service
2019-09-15 00:41:58 +00:00
dest: /etc/systemd/system/nodered.service
timeout: "{{ download_timeout }}"
- name: Replace every '[=/]pi' with '[=/]{{ nodered_linux_user }}' (nodered_linux_user) in /etc/systemd/system/nodered.service
replace:
path: /etc/systemd/system/nodered.service
regexp: '([=/])pi' # e.g. nodered_linux_user: nodered
replace: '\1{{ nodered_linux_user }}' # \1 is a back-reference to above '=' or '/' -- like sed, but Ansible uses https://docs.python.org/3/library/re.html
2019-09-15 00:41:58 +00:00
# SEE ALSO THE apache2_module SECTION IN roles/httpd/tasks/main.yml
2021-07-01 18:22:43 +00:00
#- name: Enable proxy_wstunnel apache2 module
# apache2_module:
# state: present
# name: proxy_wstunnel
2019-09-15 00:41:58 +00:00
2020-01-30 09:00:00 +00:00
# RECORD Node-RED AS INSTALLED
- name: "Set 'nodered_installed: True'"
set_fact:
nodered_installed: True
- name: "Add 'nodered_installed: True' to {{ iiab_state_file }}"
2019-09-15 00:41:58 +00:00
lineinfile:
path: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
2019-09-15 00:41:58 +00:00
regexp: '^nodered_installed'
2019-10-07 17:11:21 +00:00
line: 'nodered_installed: True'