1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-03-09 15:40:17 +00:00

Merge pull request #2604 from holta/mongodb-for-deb11-v3

Clean MongoDB/Sugarizer for Debian 11/Sid & All OS's
This commit is contained in:
A Holt 2020-10-31 23:38:05 -04:00 committed by GitHub
commit cb1fa8c648
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 107 additions and 115 deletions

View file

@ -35,9 +35,10 @@
path: /etc/iiab/diag
mode: '0777'
- name: Re-read local_facts.facts from /etc/ansible/facts.d
setup:
filter: ansible_local
# 2020-10-29: Appears no longer nec (see 3 above ansible_local.local_facts.*)
#- name: Re-read local_facts.facts from /etc/ansible/facts.d
# setup:
# filter: ansible_local
- name: Pre-check that IIAB's "XYZ_install" + "XYZ_enabled" vars (1) are defined, (2) are boolean-not-string variables, and (3) contain plausible values. Also checks that "XYZ_install" is True when "XYZ_installed" is defined.
include_tasks: validate_vars.yml
@ -167,4 +168,4 @@
when: is_VM is defined
- name: STAGE 0 HAS COMPLETED ======================================
meta: noop
command: echo # "name: XYZ" fails to appear with "meta: noop"

View file

@ -0,0 +1,13 @@
- name: Enable & (Re)Start 'mongodb.service' if mongodb_enabled
systemd:
name: mongodb
enabled: yes
state: restarted
when: mongodb_enabled
- name: Disable & Stop 'mongodb.service' if not mongodb_enabled
systemd:
name: mongodb
enabled: no
state: stopped
when: not mongodb_enabled

View file

@ -19,7 +19,7 @@
- name: Download & unzip 20MB http://download.iiab.io/packages/mongodb_stretch_3_0_14_core.zip to /tmp/mongodb-3.0.1x (aarch32)
unarchive:
remote_src: yes
src: "{{ iiab_download_url }}/mongodb_stretch_3_0_14_core.zip"
src: "{{ iiab_download_url }}/mongodb_stretch_3_0_14_core.zip" # http://download.iiab.io/packages
dest: /tmp/mongodb-3.0.1x
- name: Install (move) its 3 CORE binaries from /tmp/mongodb-3.0.1x/core to /usr/bin (aarch32)
@ -47,24 +47,22 @@
home: /var/lib/mongodb
shell: /usr/sbin/nologin
- name: Install /etc/mongod.conf from template (aarch32)
- name: Install {{ mongodb_conf }} from template (aarch32)
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: "{{ item.mode }}"
with_items:
- { src: 'mongod.conf.j2', dest: "{{ mongodb_conf }}", mode: '0644' } # i.e. /etc/mongod.conf
src: mongod.conf.j2
dest: "{{ mongodb_conf }}" # /etc/mongod.conf
#owner: root
#group: root
#mode: 0644
# end block
when: not (ansible_architecture == "x86_64" or ansible_architecture == "aarch64")
# 32 bit OS's get caught above should handle aarch32 including 32-bit ubuntu
# from https://ubuntu.com/download/raspberry-pi. 20.4-32bit might fail untested
# 32bit intel might puke as this was orginally deployed for raspbian. Haven't
# see bootable 32bit intel installers for a while now.
# 64 bit OS's proceed below.
# 32-bit OS's are handled above: this should handle aarch32 including 32-bit Ubuntu
# from https://ubuntu.com/download/raspberry-pi but Ubuntu 20.04 32-bit might fail
# untested, and 32-bit Intel might puke as this was orginally deployed for Raspbian.
# (Haven't seen bootable 32-bit Intel installers for a while now.)
# 64-bit OS's proceed below.
- block:
- name: Add mongodb.org signing key (only 64-bit support available)
@ -74,7 +72,11 @@
- name: Use mongodb-org's Debian repo for Debian (only amd64 support available)
apt_repository:
repo: deb http://repo.mongodb.org/apt/debian {{ ansible_distribution_release }}/mongodb-org/4.4 main
# 2020-10-28: http://repo.mongodb.org/apt/debian/dists/ supports only
# {buster 10, stretch 9, jessie 8, wheezy 7}
# so Debian 11 "Bullseye" (testing branch) can revert to buster for now:
repo: deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main
#repo: deb http://repo.mongodb.org/apt/debian {{ ansible_distribution_release }}/mongodb-org/4.4 main
state: present
filename: mongodb-org
when: is_debian and (ansible_architecture == "x86_64")
@ -112,12 +114,12 @@
- mongodb-org-server
state: present
- name: Change the mongodb port to 27018
- name: Change {{ mongodb_conf }} port to {{ mongodb_port }} -- takes effect on next (re)start of the service -- via enable-or-disable.yml or via sugarizer.service auto-starting MongoDB on demand
lineinfile:
path: /etc/mongod.conf
regexp: 'port: 27017'
path: "{{ mongodb_conf }}"
regexp: "port: 27017"
backrefs: yes
line: ' port: 27018'
line: " port: {{ mongodb_port }}" # 27018
# end block
when: (ansible_architecture == "aarch64") or (ansible_architecture == "x86_64")
@ -135,7 +137,7 @@
#- { path: '/var/run/mongodb' }
- /var/lib/mongodb
- /var/log/mongodb
- "{{ mongodb_db_path }}" # i.e. /library/dbdata/mongodb/
- "{{ mongodb_db_path }}" # /library/dbdata/mongodb
- name: Install mongodb.service, /usr/bin/iiab-mongodb-repair-if-no-lock from templates
template:
@ -148,14 +150,9 @@
- { src: 'mongodb.service.j2', dest: '/etc/systemd/system/mongodb.service', mode: '0644' }
- { src: 'iiab-mongodb-repair-if-no-lock.j2', dest: '/usr/bin/iiab-mongodb-repair-if-no-lock', mode: '0755' }
# daemon_reload is used to force systemd to recognize a newly installed .service file
# restarted here to ensure the port has been changed
- name: Disable 'mongodb' systemd service - started on demand by sugarizer
- name: systemctl daemon_reload, so systemd (re)reads mongodb.service
systemd:
name: mongodb
daemon_reload: yes
enabled: no
state: restarted
# 3. RECORD MongoDB AS INSTALLED

View file

@ -26,6 +26,10 @@
var: mongodb_installed
- debug:
var: rpi_model # 0-init sets it from ansible_local.local_facts.rpi_model
- debug:
var: ansible_local.local_facts.os_ver # Like OS_VER in /etc/iiab/iiab.env
- debug:
var: is_debian
- debug:
@ -39,19 +43,16 @@
ignore_errors: yes
# ELSE...
- name: Install MongoDB if 'mongodb_installed' not defined, e.g. in {{ iiab_state_file }} # /etc/iiab/iiab_state.yml
include_tasks: install.yml
when: mongodb_installed is undefined and not (ansible_architecture == "aarch64" and is_debian_10 and not is_raspbian)
- name: Disable & Stop 'mongodb' service, if not mongodb_enabled
systemd:
name: mongodb
enabled: no
state: stopped
when: not mongodb_enabled and mongodb_installed is defined
#'mongodb' systemd service - started on demand by sugarizer
# Just recording that mongodb should be running
- name: Enable or Disable MongoDB, if mongodb_installed is defined (sugarizer.service auto-starts MongoDB as nec, so doesn't need this or care what happens here!)
include_tasks: enable-or-disable.yml
when: mongodb_installed is defined
- name: Add 'mongodb' variable values to {{ iiab_ini_file }}
ini_file:

View file

@ -1,12 +0,0 @@
- name: Enable http://box/sugarizer & http://box/sugar via Apache
command: a2ensite sugarizer.conf
when: sugarizer_enabled
- name: Disable http://box/sugarizer & http://box/sugar via Apache
command: a2dissite sugarizer.conf
when: not sugarizer_enabled
- name: (Re)Start '{{ apache_service }}' systemd service
systemd:
name: "{{ apache_service }}" # apache2 or httpd, as set in /opt/iiab/iiab/vars/<OS>.yml
state: restarted

View file

@ -0,0 +1,32 @@
- name: Enable & (Re)Start 'sugarizer.service' (WHICH AUTO-STARTS BUT DOES NOT ENABLE OR DISABLE 'mongodb.service', LIKEWISE WE DON'T TOUCH ANSIBLE VAR mongodb_enabled) if sugarizer_enabled
systemd:
name: sugarizer
enabled: yes
state: restarted
when: sugarizer_enabled
- name: Disable & Stop 'sugarizer.service' (BUT LEAVE 'mongodb.service' COMPLETELY UNCHANGED, LIKEWISE WE DON'T TOUCH ANSIBLE VAR mongodb_enabled) if not sugarizer_enabled
systemd:
name: sugarizer
enabled: no
state: stopped
when: not sugarizer_enabled
- name: Enable http://box/sugarizer if sugarizer_enabled, by installing {{ nginx_conf_dir }}/sugarizer-nginx.conf from template
template:
src: sugarizer-nginx.conf
dest: "{{ nginx_conf_dir }}/sugarizer-nginx.conf" # /etc/nginx/conf.d
when: sugarizer_enabled
- name: Disable http://box/sugarizer if not sugarizer_enabled, by removing {{ nginx_conf_dir }}/sugarizer-nginx.conf
file:
path: "{{ nginx_conf_dir }}/sugarizer-nginx.conf"
state: absent
when: not sugarizer_enabled
- name: Restart 'nginx' systemd service
systemd:
name: nginx
state: restarted

View file

@ -20,10 +20,11 @@
msg: "Sugarizer install cannot proceed, as Node.js is not installed."
when: nodejs_installed is undefined
- name: FAIL (STOP THE INSTALL) IF 'nodejs_version != "12.x"'
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."
when: nodejs_version != "12.x"
# 2020-10-29: No longer nec as Sugarizer works on most all versions of Node.js
#- name: FAIL (STOP THE INSTALL) IF 'nodejs_version != "12.x"'
# 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."
# when: nodejs_version != "12.x"
# 2. DOWNLOAD+LINK /opt/iiab/sugarizer
@ -153,11 +154,16 @@
src: sugarizer.service
dest: /etc/systemd/system
- name: "Install from template: /etc/{{ apache_conf_dir }}/sugarizer.conf"
template:
src: sugarizer.conf.j2
dest: "/etc/{{ apache_conf_dir }}/sugarizer.conf" # apache2/sites-available
when: apache_installed is defined
- name: systemctl daemon_reload, so systemd (re)reads sugarizer.service
systemd:
daemon_reload: yes
# 2020-10-30: PR #2604 tries a cleaner layout, with NGINX only
#- name: "Install from template: /etc/{{ apache_conf_dir }}/sugarizer.conf"
# template:
# src: sugarizer.conf.j2
# dest: "/etc/{{ apache_conf_dir }}/sugarizer.conf" # apache2/sites-available
# when: apache_installed is defined
# 3 [WAS 4] STANZAS ADDED BELOW JAN/FEB 2019, HOPING THIS MIGHT "JUST WORK"
# WITH FUTURE UPGRADES BEYOND SUGARIZER 1.1?!

View file

@ -19,25 +19,22 @@
quiet: yes
# 3 stanzas moved up from install.yml, so Debian finishes "BIG" IIAB install:
# (WITH LOUD RED WARNINGS!)
# 3 stanzas moved up from install.yml, so Debian-or-any-OS-where-MongoDB-fails
# still finish their "BIG-sized" IIAB install: (WITH LOUD RED WARNINGS!)
# If we got here sugarizer_install is True
- name: "Set 'mongodb_install: True'"
set_fact:
mongodb_install: True
# MongoDB auto-started by sugarizer.service - let's set 'mongodb_enabled: True'
# regardless - anticipating that MongoDB (should!) run on demand:
- name: "Set 'mongodb_enabled: True' when sugarizer_enabled"
set_fact:
mongodb_enabled: True
when: sugarizer_enabled
- name: 'CAUTION: IF ''mongodb.service'' IS STOPPED FOR ANY REASON, IT WILL IMMEDIATELY CAUSE SUGARIZER TO FAIL ("502 Bad Gateway") !'
debug:
msg: "/etc/systemd/system/sugarizer.service Line 4 'Requires=mongodb.service' tries to auto-start MongoDB every time Sugarizer starts. IIAB (roles/mongodb/tasks/enable-or-disable.yml) tries its best to keep Ansible var 'mongodb_enabled' in sync with its systemd equivalent, i.e. the output of 'systemctl is-enabled mongodb' (as of 2020-10-29 both are typically disabled, unless other apps/services/operators choose to use MongoDB)."
- name: MONGODB - run 'mongodb' role (attempt to install MongoDB)
include_role:
name: mongodb
- name: EXIT 'sugarizer' ROLE & CONTINUE, IF 'mongodb_installed is undefined'
fail: # FORCE IT RED THIS ONCE!
msg: MongoDB INSTALLATION FAILED, perhaps because your OS is Debian 10 on aarch64? Nevertheless IIAB will continue (consider this a warning!)

View file

@ -2,38 +2,8 @@
include_tasks: install.yml
when: sugarizer_installed is undefined
- block: # 2 STANZAS BELOW, CONDITIONED ON 'when: sugarizer_enabled'
# LIKELY UNNEC: THIS SAME CODE IS IN main.yml (LINES 32-35, ALREADY RUN)
# sugarizer.service line 'Requires=mongodb.service' auto-starts MongoDB (but record that in var too)
- name: "Set 'mongodb_enabled: True' if sugarizer_enabled"
set_fact:
mongodb_enabled: True
- name: Enable & Restart 'sugarizer' systemd service, if sugarizer_enabled
systemd:
name: sugarizer
daemon_reload: yes # In case mongodb.service changed, etc
enabled: yes
state: restarted
when: sugarizer_enabled # CONDITION FOR 2-STANZA block: ABOVE
# Stops 'sugarizer' but not 'mongodb'
- name: Disable & Stop 'sugarizer' systemd service, if not sugarizer_enabled
systemd:
name: sugarizer
enabled: no
state: stopped
when: not sugarizer_enabled
- name: Enable/Disable/Restart Apache if primary
include_tasks: apache.yml
when: not nginx_enabled
- name: Enable/Disable/Restart NGINX if primary
include_tasks: nginx.yml
when: nginx_enabled
- include_tasks: enable-or-disable.yml
- name: Add 'sugarizer' variable values to {{ iiab_ini_file }}

View file

@ -1,16 +0,0 @@
- name: Enable http://box/sugarizer via NGINX, by installing {{ nginx_conf_dir }}/sugarizer-nginx.conf from template
template:
src: sugarizer-nginx.conf
dest: "{{ nginx_conf_dir }}/sugarizer-nginx.conf" # /etc/nginx/conf.d
when: sugarizer_enabled
- name: Disable http://box/sugarizer via NGINX, by removing {{ nginx_conf_dir }}/sugarizer-nginx.conf
file:
path: "{{ nginx_conf_dir }}/sugarizer-nginx.conf" # /etc/nginx/conf.d
state: absent
when: not sugarizer_enabled
- name: Restart 'nginx' systemd service
systemd:
name: nginx
state: restarted

View file

@ -728,6 +728,9 @@ is_fedora_18: False
# 4. Likewise behind the scenes:
# ./iiab-configure (uses iiab-from-cmdline.yml)
# Admin Console (uses iiab-from-console.yml)
# 5. roles/0-init/tasks/main.yml reads from /etc/ansible/facts.d file(s)
# local_facts.facts (but not admin_facts.fact ?)
# 6. /etc/iiab/iiab.env is created by roles/1-prep/templates/iiab.env.j2
#
# More details, including Order of Execution and Precedence:
# https://github.com/iiab/iiab/wiki/IIAB-Variables