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/main.yml

245 lines
10 KiB
YAML
Raw Normal View History

2019-01-30 00:07:08 +00:00
- name: Fail if nodejs_version is not set to 10.x
2019-01-30 00:01:03 +00:00
fail:
msg: "Sugarizer install cannot proceeed, as it currently requires Node.js 10.x, and your nodejs_version is set to {{ nodejs_version }}. Please check the value of nodejs_version in /opt/iiab/iiab/vars/default_vars.yml and possibly also /etc/iiab/local_vars.yml"
when: sugarizer_install and (nodejs_version != "10.x")
2018-07-11 23:51:10 +00:00
# 0. CLEAN UP PRIOR VERSIONS OF SUGARIZER (NEEDS WORK!)
2019-01-29 16:11:15 +00:00
# - name: Wipe /library/www/html/sugarizer* if installing sugarizer-1.0
# shell: "rm -rf {{ doc_root }}/sugarizer*"
# args:
# warn: no
2019-01-29 16:18:20 +00:00
# when: sugarizer_dir_version == "sugarizer-1.0"
2018-10-31 19:09:21 +00:00
2018-07-14 20:43:39 +00:00
# 1. 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-01-29 16:11:15 +00:00
dest: "{{ sugarizer_location }}/{{ 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
2018-05-17 22:23:44 +00:00
when: internet_available
2019-01-29 16:18:20 +00:00
- name: Create symlink /opt/iiab/sugarizer -> /opt/iiab/{{ sugarizer_dir_version }}
file:
2019-01-29 16:11:15 +00:00
src: "{{ sugarizer_location }}/{{ sugarizer_dir_version }}"
dest: "{{ sugarizer_location }}/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
2018-07-14 20:43:39 +00:00
# 2. 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-01-29 16:11:15 +00:00
dest: "{{ sugarizer_location }}/{{ 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
2018-07-12 00:12:30 +00:00
when: internet_available
2019-01-29 18:22:31 +00:00
- name: Create symlink /opt/iiab/sugarizer-server -> /opt/iiab/{{ sugarizer_server_dir_version }}
2018-05-17 22:23:44 +00:00
file:
2019-01-29 16:11:15 +00:00
src: "{{ sugarizer_location }}/{{ sugarizer_server_dir_version }}"
2018-05-17 22:23:44 +00:00
dest: "{{ sugarizer_location }}/sugarizer-server"
state: link
2018-10-31 19:09:21 +00:00
2018-07-11 23:51:10 +00:00
# 3. INSTALL A GOOD VERSION OF Node.js AND npm
2019-01-16 16:41:46 +00:00
2019-01-29 16:11:15 +00:00
# 2019-01-16/29: @jvonau's PR #1403 moved install of Node.js (10.x for now) &
2019-01-16 16:49:46 +00:00
# npm to roles/nodejs/tasks/main.yml, triggered by roles/sugarizer/meta/main.yml
2019-01-16 16:41:46 +00:00
2018-10-31 19:09:21 +00:00
2018-07-11 23:51:10 +00:00
# 4. RUN "npm install" TO POPULATE ~35MB /opt/iiab/sugarizer-server/node_modules
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-29 16:18:20 +00:00
#- name: Check for /opt/iiab/{{ sugarizer_server_dir_version }}/node_modules
2018-07-14 13:22:50 +00:00
# stat:
2019-01-29 16:18:20 +00:00
# path: "{{ sugarizer_location }}/{{ sugarizer_server_dir_version }}/node_modules"
2018-07-14 13:22:50 +00:00
# register: nmtest
# ignore_errors: true
#
#- 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
# remove --allow-root in favore of --unsafe-perm=true alone. But this needs
# 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)
2019-01-30 00:46:49 +00:00
- name: Run 'npm install --allow-root --unsafe-perm=true' to create /opt/iiab/{{ sugarizer_server_dir_version }}/node_modules (CAN TAKE ~5 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-01-29 16:18:20 +00:00
chdir: "{{ sugarizer_location }}/{{ sugarizer_server_dir_version }}"
#creates: "{{ sugarizer_location }}/{{ sugarizer_server_dir_version }}/node_modules" # OLD WAY 2
2018-07-14 18:25:12 +00:00
when: internet_available # "npm install" generally requires Internet access
# 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
2018-07-14 13:22:50 +00:00
#- name: Create the express framework for Node.js (Fedora 18)
# shell: npm install
# args:
# chdir: "{{ sugarizer_location }}/sugarizer/server"
2018-07-14 18:25:12 +00:00
# when: internet_available and is_F18 and not node_modules_exists
2017-09-04 18:43:00 +00:00
2018-08-23 00:31:02 +00:00
# Add a nodejs express function that appends a prefix to urls
- name: Install path prefix proxy
command: npm install --allow-root --unsafe-perm=true path-prefix-proxy
args:
2019-01-29 16:18:20 +00:00
chdir: "{{ sugarizer_location }}/{{ sugarizer_server_dir_version }}"
2018-08-23 00:31:02 +00:00
when: internet_available
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
2019-01-30 22:34:59 +00:00
- name: "Install from templates: sugarizer.service (systemd), sugarizer.conf (Apache)"
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
2018-05-22 16:52:31 +00:00
mode: "{{ item.mode }}"
owner: root
group: root
2017-05-27 18:09:50 +00:00
with_items:
2019-01-31 00:13:03 +00:00
- { src: 'sugarizer.service', dest: '/etc/systemd/system/sugarizer.service', mode: '0644' }
2019-01-30 22:34:59 +00:00
- { src: 'sugarizer.conf.j2', dest: '/etc/apache2/sites-available/sugarizer.conf', mode: '0644' }
2019-01-31 00:13:03 +00:00
#- { src: 'sugarizer.ini.j2', dest: '{{ sugarizer_location }}/{{ sugarizer_server_dir_version }}/env/sugarizer.ini', mode: '0644' }
#- { src: 'sugarizer.js', dest: '{{ sugarizer_location }}/{{ sugarizer_server_dir_version }}', mode: '0644' }
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-01-31 00:17:02 +00:00
path: /opt/iiab/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 }}"
# 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
# SEE https://github.com/iiab/iiab/pull/1430#issuecomment-459129378
- name: Customize pathPrefix /sugarizer in /opt/iiab/sugarizer-server/sugarizer.js
lineinfile:
path: /opt/iiab/sugarizer-server/sugarizer.js
insertbefore: "^// Start listening$"
block: "var pathPrefix = '/sugarizer';\napp.use(pathPrefix, require('path-prefix-proxy')(pathPrefix));\n\n"
# block: |+
# var pathPrefix = '/sugarizer';
# app.use(pathPrefix, require('path-prefix-proxy')(pathPrefix));
2017-05-27 18:09:50 +00:00
2018-10-31 19:09:21 +00:00
- name: Create symlink sugarizer.conf from sites-enabled to sites-available, for short URL http://box/sugarizer (debuntu)
2018-07-11 17:06:37 +00:00
file:
src: /etc/apache2/sites-available/sugarizer.conf
2018-10-31 19:09:21 +00:00
path: /etc/apache2/sites-enabled/sugarizer.conf
2018-07-11 17:06:37 +00:00
state: link
2018-10-31 19:09:21 +00:00
when: sugarizer_enabled and is_debuntu
2018-10-31 19:13:28 +00:00
- name: "Remove symlink /etc/apache2/sites-enabled/sugarizer.conf, if sugarizer_enabled: False (debuntu)"
2018-10-31 19:09:21 +00:00
file:
path: /etc/apache2/sites-enabled/sugarizer.conf
state: absent
when: not sugarizer_enabled and is_debuntu
2017-05-27 18:09:50 +00:00
2018-07-11 23:51:10 +00:00
# 6. RESTART/STOP SYSTEMD SERVICE
2017-05-27 18:09:50 +00:00
2018-10-31 19:09:21 +00:00
- name: Enable & Restart systemd service if sugarizer_enabled, with "systemctl daemon-reload" (in case mongodb.service changed?)
2018-07-22 15:22:30 +00:00
systemd:
name: sugarizer
2019-01-29 16:11:15 +00:00
daemon_reload: yes
enabled: yes
state: restarted
2017-09-22 07:14:14 +00:00
when: sugarizer_enabled
2018-08-23 03:04:04 +00:00
2018-10-31 19:09:21 +00:00
- name: "Disable systemd service, if sugarizer_enabled: False"
2018-07-22 15:22:30 +00:00
systemd:
2018-07-14 17:46:38 +00:00
name: sugarizer
enabled: no
state: stopped
2017-09-22 07:14:14 +00:00
when: not sugarizer_enabled
2017-05-27 18:09:50 +00:00
2018-10-31 19:09:21 +00:00
- name: Restart Apache ({{ apache_service }}) to enable/disable http://box/sugarizer (not just http://box:8089)
systemd:
name: "{{ apache_service }}" # httpd or apache2
state: restarted
#when: sugarizer_enabled
2018-07-22 15:22:30 +00:00
#- name: Enable services (all OS's)
# service:
# name: "{{ item.name }}"
# enabled: yes
# state: restarted
# with_items:
## - { name: mongodb } # 2018-07-14: NICE TRY, but still doesn't bring http://box:8089 to life reliably, as a reboot usually does! (Is a "systemctl daemon-reload" or some such nec?)
# - { name: sugarizer }
# when: sugarizer_enabled
#- name: Disable service (all OS's)
# service:
# name: sugarizer
# enabled: no
# state: stopped
# when: not sugarizer_enabled
2018-10-31 05:46:53 +00:00
- name: Add 'sugarizer' variable values to {{ iiab_ini_file }}
ini_file:
2018-10-31 05:46:53 +00:00
path: "{{ iiab_ini_file }}"
2017-11-20 04:02:07 +00:00
section: sugarizer
option: "{{ item.option }}"
value: "{{ item.value }}"
2017-05-27 18:09:50 +00:00
with_items:
2017-12-08 06:20:01 +00:00
- option: name
value: Sugarizer
- option: description
value: '"The Sugar Learning Platform began with the famous One Laptop Per Child project, written in Python. Sugarizer is the new HTML/JavaScript implementation of Sugar, usable in most all browsers."'
0.3 patch1 (#1377) * expand zim_versions_idx to include menuItem name, mediaCount, articleCount, size * create a stub menuItem if none exists * remember to change consumer of zim_version_idx in iiab-admin * comment out some debugging prints * do not change the name of a variable in iiab.ini * consistent variable names for *_enabled * start work on menus for enabled iiab roles * changes to display cups in home menu * remove reference to admin console which may not be installed * print error message * dict.get errors * handle undefined menuItem" * handle undefined menuItem again * some work on logos * break out the zim_versions_idx routines for use by update_menus in admin-console * remove old menuDef creation code * new variable names for zim_versions_idx * missing the tags data in zim_versions_idx * un-break-apart iiab-make-kiwix-lib.py * return an empty string * make size human_readable * getting console and iiab to work together on menus * add the new zim_date field to zim_versions_idx * get the latest into repo * found lost code iiab-make-kiwix-lib.py * Create Lokole admin user during setup * Add requested content to lokole readme Per iiab/iiab#1293 * Update default password * Add Lokole-IIAB user manual * Update default_vars.yml * Update local_vars_min.yml * Update local_vars_min.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update default_vars.yml * Update default_vars.yml * Update local_vars_min.yml * Update local_vars_medium.yml * Update local_vars_big.yml * Update default_vars.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Change admin username to uppercase * Revert "Lokole: change admin to Admin per IIAB app norms" * Update main.yml * Update README.rst * Update capture-wsgi.py * Update main.yml * Update main.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Update main.yml * Update main.yml * Update main.yml * Update main.yml * Update default_vars.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_min.yml * Address TODOs in Lokole documentation See https://github.com/ascoderu/opwen-webapp/issues/81 * Update main.yml * Update local_vars_big.yml * Update local_vars_medium.yml * Update local_vars_big.yml * Update local_vars_min.yml * Update default_vars.yml * expand zim_versions_idx to include menuItem name, mediaCount, articleCount, size * create a stub menuItem if none exists * remember to change consumer of zim_version_idx in iiab-admin * comment out some debugging prints * do not change the name of a variable in iiab.ini * consistent variable names for *_enabled * start work on menus for enabled iiab roles * changes to display cups in home menu * remove reference to admin console which may not be installed * print error message * dict.get errors * handle undefined menuItem" * handle undefined menuItem again * some work on logos * break out the zim_versions_idx routines for use by update_menus in admin-console * remove old menuDef creation code * new variable names for zim_versions_idx * missing the tags data in zim_versions_idx * un-break-apart iiab-make-kiwix-lib.py * return an empty string * make size human_readable * getting console and iiab to work together on menus * add the new zim_date field to zim_versions_idx * get the latest into repo * found lost code iiab-make-kiwix-lib.py
2019-01-10 22:26:47 +00:00
- option: sugarizer_enabled
2017-12-08 06:20:01 +00:00
value: "{{ sugarizer_enabled }}"