Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework + modernize Node-RED's roles/nodered install routine (no more 'pi', ETC!) #3248

Merged
merged 5 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
- name: Enable & Restart 'calibre-web' systemd service, if calibreweb_enabled
systemd:
name: calibre-web
daemon_reload: yes
enabled: yes
state: restarted
when: calibreweb_enabled

- name: Disable & Stop 'calibre-web' systemd service, if not calibreweb_enabled
systemd:
name: calibre-web
enabled: no
state: stopped
when: not calibreweb_enabled


# TO DO: restore http://box/libros & http://box/livres etc, alongside English (#2195)
# RELATED: https://github.com/janeczku/calibre-web/wiki/Setup-Reverse-Proxy

Expand Down
18 changes: 1 addition & 17 deletions roles/calibre-web/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,7 @@
when: calibreweb_installed is undefined


- name: Enable & Restart 'calibre-web' systemd service, if calibreweb_enabled
systemd:
name: calibre-web
daemon_reload: yes
enabled: yes
state: restarted
when: calibreweb_enabled

- name: Disable & Stop 'calibre-web' systemd service, if not calibreweb_enabled
systemd:
name: calibre-web
enabled: no
state: stopped
when: not calibreweb_enabled

- name: Enable/Disable/Restart NGINX
include_tasks: nginx.yml
- include_tasks: enable-or-disable.yml


- name: Add 'calibre-web' variable values to {{ iiab_ini_file }}
Expand Down
2 changes: 1 addition & 1 deletion roles/cups/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
blockinfile:
path: /etc/cups/cupsd.conf
insertafter: '^<Location /admin>$'
block: |2 # Indent with 2 spaces, and surround block with 2 comment lines: "# BEGIN ANSIBLE MANAGED BLOCK", "# END ANSIBLE MANAGED BLOCK"
block: |2 # |n MEANS: Set the block's left edge n CHARACTERS TO THE RIGHT of *this line's* indentation -- where n is {1..9} -- instead of setting its left edge to the 1st non-blank line's indentation below. Also surround block with comment lines: "# BEGIN ANSIBLE MANAGED BLOCK", "# END ANSIBLE MANAGED BLOCK"
AuthType Default
Require user @SYSTEM

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
- name: Enable & Start 'kolibri' systemd service, if kolibri_enabled
systemd:
name: kolibri
daemon_reload: yes
enabled: yes
state: started
when: kolibri_enabled

- name: Disable & Stop 'kolibri' systemd service, if not kolibri_enabled
systemd:
name: kolibri
enabled: no
state: stopped
when: not kolibri_enabled


- name: Enable http://box{{ kolibri_url }} via NGINX, by installing {{ nginx_conf_dir }}/kolibri-nginx.conf from template # http://box/kolibri
template:
src: kolibri-nginx.conf.j2
Expand Down
18 changes: 1 addition & 17 deletions roles/kolibri/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,7 @@
when: kolibri_installed is undefined


- name: Enable & Start 'kolibri' systemd service, if kolibri_enabled
systemd:
name: kolibri
daemon_reload: yes
enabled: yes
state: started
when: kolibri_enabled

- name: Disable & Stop 'kolibri' systemd service, if not kolibri_enabled
systemd:
name: kolibri
enabled: no
state: stopped
when: not kolibri_enabled

- name: Enable/Disable/Restart NGINX
include_tasks: nginx.yml
- include_tasks: enable-or-disable.yml


- name: Add 'kolibri' variable values to {{ iiab_ini_file }} # /etc/iiab/iiab.ini
Expand Down
1 change: 0 additions & 1 deletion roles/nextcloud/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

- name: Enable/Disable/Restart NGINX
include_tasks: nginx.yml
when: nginx_enabled


- name: Add 'nextcloud' variable values to {{ iiab_ini_file }}
Expand Down
7 changes: 4 additions & 3 deletions roles/nodered/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
# All above are set in: github.com/iiab/iiab/blob/master/vars/default_vars.yml
# If nec, change them by editing /etc/iiab/local_vars.yml prior to installing!

nodered_user: Admin
nodered_password: changeme # REMOVE THIS PASSWORD REMINDER LINE AS NECESSARY
nodered_password_hash: $2b$08$oxgvoU9et3deSbXY8UNVTOWHSTQAyEASIal86RHVMqYQJhpPMNz7q
nodered_linux_user: nodered

nodered_admin_user: Admin
nodered_admin_pwd_hash: $2b$08$oxgvoU9et3deSbXY8UNVTOWHSTQAyEASIal86RHVMqYQJhpPMNz7q # Password itself is "changeme"

# TO GENERATE A NEW PASSWORD HASH, run 'node-red-admin hash-pw' and enter
# the new password. Paste the resulting hash as above, but into your own:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
- name: Enable & (Re)start 'nodered' systemd service, if nodered_enabled
systemd:
name: nodered
daemon_reload: yes
enabled: yes
state: restarted
when: nodered_enabled

- name: Disable & Stop 'nodered' systemd service, if not nodered_enabled
systemd:
name: nodered
enabled: no
state: stopped
when: not nodered_enabled


- name: Enable http://box/nodered via NGINX, by installing {{ nginx_conf_dir }}/nodered-nginx.conf from template
template:
src: nodered-nginx.conf.j2
Expand All @@ -6,7 +22,7 @@

- name: Disable http://box/nodered via NGINX, by removing {{ nginx_conf_dir }}/nodered-nginx.conf
file:
path: "{{ nginx_conf_dir }}/nodered-nginx.conf" # /etc/nginx/conf.d
path: "{{ nginx_conf_dir }}/nodered-nginx.conf"
state: absent
when: not nodered_enabled

Expand Down
26 changes: 0 additions & 26 deletions roles/nodered/tasks/group.yml

This file was deleted.

67 changes: 47 additions & 20 deletions roles/nodered/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
msg: "Node-RED install cannot proceed, as Node.js is not installed."
when: nodejs_installed is undefined

# 2020-10-29: not really be nec as Node-RED supports recent Node.js versions
# 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."
Expand All @@ -36,23 +36,29 @@
package:
name: nodered
state: absent
when: nodered_install

# 2019-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
#command: npm install -g --unsafe-perm node-red@latest node-red-admin@latest node-red-dashboard@latest
# Above "@latest" is recommended by https://nodered.org/docs/hardware/raspberrypi (SHOULD WE CONSIDER?)
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 is_raspbian
# 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"

## 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
Expand Down Expand Up @@ -89,18 +95,39 @@
# creates: /usr/lib/node_modules/node-red-dashboard
# when: nodered_install and internet_available

- include_tasks: group.yml
when: nodered_install and not is_raspbian
- include_tasks: settings.yml
#when: not is_raspbian

- include_tasks: rpi_desk.yml
when: nodered_install and is_raspbian
- include_tasks: os-integration.yml
#- include_tasks: rpi_desk.yml
# when: is_raspbian

- name: Install /etc/systemd/system/nodered.service systemd unit file from template
template:
backup: no
src: nodered.service.j2
# 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
dest: /etc/systemd/system/nodered.service
# mode: '0666'
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

# SEE ALSO THE apache2_module SECTION IN roles/httpd/tasks/main.yml
#- name: Enable proxy_wstunnel apache2 module
Expand Down
18 changes: 1 addition & 17 deletions roles/nodered/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,7 @@
when: nodered_installed is undefined


- name: Enable & (Re)start 'nodered' systemd service, if nodered_enabled
systemd:
name: nodered
daemon_reload: yes
enabled: yes
state: restarted
when: nodered_enabled

- name: Disable & Stop 'nodered' systemd service, if not nodered_enabled
systemd:
name: nodered
enabled: no
state: stopped
when: not nodered_enabled

- name: Enable/Disable/Restart NGINX
include_tasks: nginx.yml
- include_tasks: enable-or-disable.yml


- name: Add 'nodered' variable values to {{ iiab_ini_file }}
Expand Down
68 changes: 68 additions & 0 deletions roles/nodered/tasks/os-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# 2022-06-08: This file used to be rpi_desk.yml

# 2022-06-09: Crucially, the 3 "dest" dirs (below) exist on all mainline OS's
- name: "Download 3 Node-RED enhancements: Node-RED icon, start menu item, /etc/logrotate.d/nodered"
get_url:
url: "{{ item.url }}"
dest: "{{ item.dest }}"
force: yes
timeout: "{{ download_timeout }}"
with_items:
- url: https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-icon.svg
dest: /usr/share/icons/hicolor/scalable/apps/node-red-icon.svg
- url: https://raw.githubusercontent.com/node-red/linux-installers/master/resources/Node-RED.desktop
dest: /usr/share/applications/Node-RED.desktop
- url: https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.rotate
dest: /etc/logrotate.d/nodered
# 2022-06-08: New versions above, pasted from https://github.com/node-red/linux-installers/blob/master/deb/update-nodejs-and-nodered
# - 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'

#- 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_raspbian

#- name: 'Download/Install 4 RPi executables to /usr/bin: node-red-start, node-red-stop, node-red-restart, node-red-log'
- name: 'Install 5 executables to /usr/bin: node-red-start, node-red-stop, node-red-restart, node-red-reload, node-red-log'
get_url:
url: "{{ item }}"
dest: /usr/bin
mode: a+x
force: yes
timeout: "{{ download_timeout }}"
with_items:
- https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-start
- https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-stop
- https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-restart
- https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-reload
- https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-log
# 2022-08-06: New versions above, pasted from https://github.com/node-red/linux-installers/blob/master/deb/update-nodejs-and-nodered
# - 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

# 2022-06-08 #3245: Raspberry Pi OS recently removed the 'pi' user. For now,
# until converging on a longer-term strategy, let's comment out both stanzas:

# - name: Create /home/pi/.node-red/ directory (rpi)
# file:
# path: /home/pi/.node-red
# state: directory
# owner: pi
# group: pi
# mode: 0775

# - name: Install /home/pi/.node-red/settings.js from template, with authentication (rpi)
# template:
# src: settings.js.j2
# dest: /home/pi/.node-red/settings.js
# owner: pi
# group: pi
# mode: 0755