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

246 lines
12 KiB
YAML
Raw Normal View History

# 0. INSTALL/ASSERT PREREQ #1: MongoDB
2020-01-29 15:08:18 +00:00
# 3 stanzas moved up to main.yml, so Debian finishes "BIG-sized" IIAB install
# (WITH LOUD RED WARNINGS!)
2020-01-30 09:00:00 +00:00
# 1. INSTALL/ASSERT PREREQ #2: Node.js
- name: "Set 'nodejs_install: True' and 'nodejs_enabled: True'"
2020-01-30 09:00:00 +00:00
set_fact:
2020-01-29 16:41:56 +00:00
nodejs_install: True
nodejs_enabled: True
2020-01-05 03:54:01 +00:00
- name: NODEJS - run 'nodejs' role (attempt to install & enable Node.js)
2020-01-05 03:54:01 +00:00
include_role:
name: nodejs
- name: FAIL (STOP THE INSTALL) IF 'nodejs_installed is undefined'
2019-01-30 00:01:03 +00:00
fail:
msg: "Sugarizer install cannot proceed, as Node.js is not installed."
2020-01-29 16:41:56 +00:00
when: nodejs_installed is undefined
- name: FAIL (STOP THE INSTALL) IF 'nodejs_version != "12.x"'
2020-01-29 16:41:56 +00:00
fail:
msg: "Sugarizer 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."
2020-01-29 16:41:56 +00:00
when: nodejs_version != "12.x"
2020-01-30 09:00:00 +00:00
# 2. DOWNLOAD+LINK /opt/iiab/sugarizer
2019-01-29 22:21:42 +00:00
- name: Clone llaske/sugarizer ({{ sugarizer_git_version }} branch/version) from GitHub to /opt/iiab/{{ sugarizer_dir_version }} (MAY DOWNLOAD 600+ MB)
2018-07-11 23:51:10 +00:00
git:
repo: https://github.com/llaske/sugarizer
2019-02-02 20:32:39 +00:00
dest: "{{ iiab_base }}/{{ sugarizer_dir_version }}"
2018-07-11 23:51:10 +00:00
version: "{{ sugarizer_git_version }}"
2018-07-12 01:27:40 +00:00
force: yes
2018-07-13 01:04:04 +00:00
depth: 1
when: internet_available | bool
2018-05-17 22:23:44 +00:00
2020-02-18 01:45:16 +00:00
- name: Symlink /opt/iiab/sugarizer -> /opt/iiab/{{ sugarizer_dir_version }}
file:
2019-02-02 20:32:39 +00:00
src: "{{ iiab_base }}/{{ sugarizer_dir_version }}"
dest: "{{ iiab_base }}/sugarizer"
2017-11-20 04:09:54 +00:00
state: link
2017-05-27 18:09:50 +00:00
2018-10-31 19:09:21 +00:00
# 3. DOWNLOAD+LINK /opt/iiab/sugarizer-server
2018-07-11 23:51:10 +00:00
2018-07-14 20:43:39 +00:00
# 2018-07-11: http://download.iiab.io/packages/sugarizer-server-1.0.tar.gz
2018-07-12 01:27:40 +00:00
# was flawed, as documented at:
# https://github.com/iiab/iiab/pull/814#issuecomment-404211098
# Versions of MongoDB, npm (& Node.js ?) matter! Sugarizer 1.0 Context:
2018-07-11 23:51:10 +00:00
# https://github.com/iiab/iiab/issues/798
# Going forward let's "git clone" IIAB's preferred versions, of sugarizer
2018-07-12 01:29:49 +00:00
# AND sugarizer-server, as specified in roles/sugarizer/defaults/main.yml
2018-07-14 16:25:58 +00:00
# 2018-07-14 BLOAT: git works well BUT even with "depth: 1"
2018-07-14 13:22:50 +00:00
# - 229MB is unfort downloaded to /opt/iiab/sugarizer/.git
# - 1.4MB is unfort downloaded to /opt/iiab/sugarizer-server/.git
2018-07-14 18:01:20 +00:00
# CLARIF: during repeat runs of "./runrole sugarizer", this git sync shows
# "changed" (whereas above git sync shows "ok"). Reason: "npm install"
# (below) modifies /opt/iiab/sugarizer-server/node_modules
2019-01-29 22:21:42 +00:00
- name: Clone llaske/sugarizer-server ({{ sugarizer_server_git_version }} branch/version) from GitHub to /opt/iiab/{{ sugarizer_server_dir_version }}
git:
2018-07-11 23:11:29 +00:00
repo: https://github.com/llaske/sugarizer-server
2019-02-02 20:32:39 +00:00
dest: "{{ iiab_base }}/{{ sugarizer_server_dir_version }}"
2018-07-11 23:51:10 +00:00
version: "{{ sugarizer_server_git_version }}"
2018-07-12 01:27:40 +00:00
force: yes
2018-07-13 01:04:04 +00:00
depth: 1
when: internet_available | bool
2020-02-18 01:45:16 +00:00
- name: Symlink /opt/iiab/sugarizer-server -> /opt/iiab/{{ sugarizer_server_dir_version }}
2018-05-17 22:23:44 +00:00
file:
2019-02-02 20:32:39 +00:00
src: "{{ iiab_base }}/{{ sugarizer_server_dir_version }}"
dest: "{{ iiab_base }}/sugarizer-server"
2018-05-17 22:23:44 +00:00
state: link
2018-10-31 19:09:21 +00:00
# 4. RUN "npm install" TO POPULATE ~35MB /opt/iiab/sugarizer-server/node_modules (TWICE, BIG JOB THEN SMALL JOB)
2018-07-11 23:51:10 +00:00
2018-07-15 11:22:49 +00:00
# Re-running "npm install" USED TO fail on Raspbian 9 if not other OS's ?
2018-07-15 11:10:31 +00:00
# Strategies considered to avoid re-running it:
2018-07-14 15:59:26 +00:00
# OLD WAY 1: test & set flag node_modules_exists: True
# OLD WAY 2: "creates: ..." checks for non-existence of /opt/iiab/sugarizer-server-1.0/node_modules
# OLD WAY 3: set "register: git_sug_server_output" above, then as nec delete /opt/iiab/sugarizer-server-1.0/node_modules "when: git_sug_server_output.changed" and as nec run "npm install"
2019-01-31 00:44:16 +00:00
#- name: Check for /opt/iiab/sugarizer-server/node_modules
2018-07-14 13:22:50 +00:00
# stat:
2019-02-02 20:32:39 +00:00
# path: "{{ iiab_base }}/sugarizer-server/node_modules"
2018-07-14 13:22:50 +00:00
# register: nmtest
# ignore_errors: True
2018-07-14 13:22:50 +00:00
#
#- name: Set a flag to prevent re-running of "npm install"
# set_fact:
# node_modules_exists: True
# when: nmtest.stat is defined and nmtest.stat.exists
2017-09-04 18:43:00 +00:00
2018-07-15 11:10:31 +00:00
# NEW WAY BELOW: run "npm install --allow-root" every time, as modern versions
# of npm are incremental, with sanity checks (all 3 may work: but npm 6.2.0
2018-07-15 11:16:50 +00:00
# is better than 5.6.0. which is better than Ubuntu 18.04's 3.5.2).
2018-07-15 11:10:31 +00:00
# 2018-07-15: TK Kang & Holt confirmed sudo-driven "npm install" maxes out CPU
2018-07-15 23:04:48 +00:00
# for hours, on diff OS's using npm 5.6.0 and 6.2.0. Hours later you may get
# error: code EACCES, errno -13 (permission denied),
2018-07-15 11:10:31 +00:00
# "Missing write access to /opt/iiab/sugarizer-server-1.0/node_modules"
#
# SOLUTION: Implement '--allow-root --unsafe-perm=true' below, as is critical
# for 1st run of sudo-driven 'npm install' especially:
2018-07-15 11:10:31 +00:00
#
2018-07-15 22:56:20 +00:00
# ON DEBIAN: npm 5.6.0's --allow-root would be sufficient: causing creation
# of /root/.npm cache & lock files to owned by root:root instead of
# iiab-admin:iiab-admin...thus permitting it & IIAB installs to complete!
#
2018-07-15 22:56:20 +00:00
# ON RASPBIAN: npm 5.6.0's --unsafe-perm=true is *required* so that npm
# install actually finished (in about 5 minutes). It's possible we should
2019-06-25 03:43:50 +00:00
# remove --allow-root in favor of --unsafe-perm=true alone. But this needs
2018-07-15 22:56:20 +00:00
# testing on different Linuxes before proceeding.
#
# CLARIF 1: Something like 'chown -R root:root /root/.npm' would do the job,
2018-07-15 22:56:20 +00:00
# but cannot happen synchronously throughout the 1st run of 'npm install'
# (when it's needed!) Similar to what --allow-root does on Debian.
#
# CLARIF 2: Ubuntu 18.04 is currently unaffected due to its ancient
2018-07-15 22:56:20 +00:00
# npm 3.5.2, which instead uses /home/iiab-admin/.npm (which remains owned
# by iiab-admin:iiab-admin, even with '--allow-root', but thankfully still
# gets the job done, for now!)
2018-07-15 11:10:31 +00:00
2018-07-14 13:22:50 +00:00
#- name: Create the express framework for Node.js (OS's other than Fedora 18)
- name: Run 'npm install --allow-root --unsafe-perm=true' to create /opt/iiab/sugarizer-server/node_modules (CAN TAKE ~10 MINUTES)
command: npm install --allow-root --unsafe-perm=true # "command:" a bit safer than "shell:"
2018-07-11 23:51:10 +00:00
args:
2019-02-02 20:32:39 +00:00
chdir: "{{ iiab_base }}/sugarizer-server"
#creates: "{{ iiab_base }}/sugarizer-server/node_modules" # OLD WAY 2
when: internet_available | bool # "npm install" generally requires Internet access
2018-07-14 18:25:12 +00:00
# when: internet_available and git_sug_server_output.changed # OLD WAY 3
# when: internet_available and not is_F18 and not node_modules_exists # OLD WAY 1
2019-02-02 16:12:01 +00:00
# Add a Node.js Express function that appends a prefix to URLs.
2019-02-02 22:47:47 +00:00
# SEE "AUTO-INSERTED BY IIAB" ~61 LINES BELOW: as those two "pathPrefix" lines
2019-02-02 16:12:01 +00:00
# MUST be added to /opt/iiab/sugarizer-server/sugarizer.js
2019-02-02 15:38:05 +00:00
- name: For http://box/sugarizer -- run 'npm install --allow-root --unsafe-perm=true path-prefix-proxy' to create /opt/iiab/sugarizer-server/node_modules/path-prefix-proxy
2019-01-31 00:44:16 +00:00
command: npm install --allow-root --unsafe-perm=true path-prefix-proxy
2018-08-23 00:31:02 +00:00
args:
2019-02-02 20:32:39 +00:00
chdir: "{{ iiab_base }}/sugarizer-server"
when: internet_available | bool
2018-08-23 00:31:02 +00:00
2018-10-31 19:09:21 +00:00
2019-01-30 22:34:59 +00:00
# 5. CONFIG FILES
2017-09-04 18:43:00 +00:00
2020-01-11 22:14:40 +00:00
- name: "Install from templates: /etc/systemd/system/sugarizer.service, /etc/apache2/sites-available/sugarizer.conf"
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
2020-01-11 22:14:40 +00:00
# owner: root
# group: root
# mode: '0644'
2017-05-27 18:09:50 +00:00
with_items:
2019-01-31 00:46:40 +00:00
- { src: 'sugarizer.service', dest: '/etc/systemd/system/sugarizer.service' }
2020-01-30 09:00:00 +00:00
- { src: 'sugarizer.conf.j2', dest: "/etc/{{ apache_conf_dir }}/sugarizer.conf" }
2019-02-02 20:32:39 +00:00
#- { src: 'sugarizer.ini.j2', dest: '{{ iiab_base }}/sugarizer-server/env/sugarizer.ini' }
#- { src: 'sugarizer.js', dest: '{{ iiab_base }}/sugarizer-server' }
2019-01-30 22:34:59 +00:00
2019-02-03 03:17:25 +00:00
# 3 [WAS 4] STANZAS ADDED BELOW JAN/FEB 2019, HOPING THIS MIGHT "JUST WORK"
2019-02-03 03:25:13 +00:00
# WITH FUTURE UPGRADES BEYOND SUGARIZER 1.1?!
#
# SOME BACKGROUND -- WHY WE'RE AUTO-EDITING sugarizer-server'S CONFIG FILES:
# http://github.com/iiab/iiab/pull/1430#issuecomment-459129378
2019-02-02 15:38:05 +00:00
2019-02-02 12:29:11 +00:00
# sugarizer_port is set to 8089 in /opt/iiab/iiab/vars/default_vars.yml
# If you need to change this, edit /etc/iiab/local_vars.yml prior to installing
2019-01-30 22:34:59 +00:00
- name: Set Sugarizer port to {{ sugarizer_port }} in /opt/iiab/sugarizer-server/env/sugarizer.ini
lineinfile:
2019-02-02 21:00:10 +00:00
path: "{{ iiab_base }}/sugarizer-server/env/sugarizer.ini"
2019-01-30 22:34:59 +00:00
regexp: "^port = 8080$"
2019-01-30 23:58:04 +00:00
line: "port = {{ sugarizer_port }}"
2019-02-02 22:47:47 +00:00
# 2019-02-02 No Longer Required thanks to @llaske's upstream fix:
# https://github.com/llaske/sugarizer-server/commit/46c4822bc7801ff8d621c22988aa4418359e7e19
## 2019-02-02: HACK WAS REQUIRED ON UBUNTU 18.04 so Sugarizer finds MongoDB
## after 1st reboot. Otherwise "Waiting for DB..." appears every second as
## shown by "systemctl status sugarizer" and "journalctl -eu sugarizer".
## This does NOT affect Ubuntu 16.04 or Raspbian. @jvonau wonders if U18.04's
## "nameserver 127.0.0.53" in /etc/resolv.conf is to blame? @m-anish wondered
## if "bind_ip: 127.0.0.1" in /etc/mongod.conf was to blame as suggested by
## https://stackoverflow.com/questions/8904991/mongodb-cant-connect-to-localhost-but-can-connect-to-localhosts-ip-address
## But changing to "bind_ip: localhost" does not work with Sugarizer, and
## "bind_ip: 127.0.0.1,localhost" is not allowed. BACKGROUND: PR #1430
#- name: Set MongoDB "server" from localhost to 127.0.0.1 in /opt/iiab/sugarizer-server/env/sugarizer.ini
# lineinfile:
# path: "{{ iiab_base }}/sugarizer-server/env/sugarizer.ini"
# regexp: "^server = localhost$"
# line: "server = 127.0.0.1"
2019-02-02 20:32:39 +00:00
2019-02-02 12:29:11 +00:00
# mongodb_port is set to 27018 in /opt/iiab/iiab/vars/default_vars.yml
# If you need to change this, edit /etc/iiab/local_vars.yml prior to installing
2019-01-31 06:00:20 +00:00
- name: Set MongoDB port to {{ mongodb_port }} in /opt/iiab/sugarizer-server/env/sugarizer.ini
lineinfile:
2019-02-02 21:00:10 +00:00
path: "{{ iiab_base }}/sugarizer-server/env/sugarizer.ini"
2019-01-31 06:00:20 +00:00
regexp: "^port = 27017$"
line: "port = {{ mongodb_port }}"
2019-02-02 12:29:11 +00:00
# 2-LINE FIX FOR sugarizer.js BY @georgejhunt FOR http://box/sugarizer
2019-02-02 22:47:47 +00:00
# SEE ~61 LINES ABOVE, as this is REQUIRED: 'npm install --allow-root --unsafe-perm=true path-prefix-proxy'
2019-02-02 15:38:05 +00:00
# OR YOU GET ERRORS: "status=255" within "systemctl status sugarizer"
# "Cannot find module 'path-prefix-proxy'" within "journalctl -eu sugarizer"
2019-02-02 20:32:39 +00:00
- name: For http://box/sugarizer -- add pathPrefix lines in /opt/iiab/sugarizer-server/sugarizer.js
2019-02-02 15:38:05 +00:00
lineinfile:
2019-02-02 21:00:10 +00:00
path: "{{ iiab_base }}/sugarizer-server/sugarizer.js"
2019-02-02 15:38:05 +00:00
regexp: "AUTO-INSERTED BY IIAB" # avoids inserting it twice!
insertbefore: "// Start listening$"
line: | # SEE https://yaml-multiline.info (use |+ to 'keep' newlines at end...though |8 and |+4 "indentation indicators" don't work with Ansible)
// AUTO-INSERTED BY IIAB FOR http://box/sugarizer
var pathPrefix = '/sugarizer';
app.use(pathPrefix, require('path-prefix-proxy')(pathPrefix));
# Use this instead, if tabs are truly nec:
# line: "\t// AUTO-INSERTED BY IIAB FOR http://box/sugarizer\n\tvar pathPrefix = '/sugarizer';\n\tapp.use(pathPrefix, require('path-prefix-proxy')(pathPrefix));\n"
2019-01-31 02:48:21 +00:00
# Ansible's blockinfile module:
# - inserts a mandatory marker line at beginning AND end of the block...ok fine
# - doesn't support adding a newline after the block...ugly :(
# - doesn't include above lineinfile's "regexp" parameter...and so risks inserting the block repeatedly, on each run :(
#
# blockinfile:
# path: /opt/iiab/sugarizer-server/sugarizer.js
# insertbefore: "// Start listening$"
# marker: "// {mark} AUTO-INSERTED BY IIAB FOR http://box/sugarizer"
# block: |
2019-01-30 23:58:04 +00:00
# var pathPrefix = '/sugarizer';
# app.use(pathPrefix, require('path-prefix-proxy')(pathPrefix));
2019-01-31 02:48:21 +00:00
# # Use this instead, if tabs are truly nec:
# # block: "\tvar pathPrefix = '/sugarizer';\n\tapp.use(pathPrefix, require('path-prefix-proxy')(pathPrefix));"
2017-05-27 18:09:50 +00:00
2020-01-29 15:08:18 +00:00
2020-01-30 09:00:00 +00:00
# 6. RECORD Sugarizer AS INSTALLED
2020-01-29 16:53:51 +00:00
2020-01-30 09:00:00 +00:00
- name: "Set 'sugarizer_installed: True'"
set_fact:
2020-01-29 16:53:51 +00:00
sugarizer_installed: True
2020-01-29 15:08:18 +00:00
- name: "Add 'sugarizer_installed: True' to {{ iiab_state_file }}"
2019-09-09 17:14:13 +00:00
lineinfile:
path: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
2019-09-09 17:14:13 +00:00
regexp: '^sugarizer_installed'
2019-10-07 17:11:21 +00:00
line: 'sugarizer_installed: True'