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

Merge pull request #2493 from jvonau/mongo2

RFC Mongo2 [reinforce MongoDB on most distros, e.g. for Sugarizer]
This commit is contained in:
A Holt 2020-08-27 11:18:21 -04:00 committed by GitHub
commit 5be08e2b02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 144 additions and 154 deletions

View file

@ -1,13 +1,5 @@
# 1. INSTALL MongoDB PACKAGES OR BINARIES
- name: "Install packages: mongodb, mongodb-server (not raspbian)"
package:
name:
- mongodb-server
- mongodb # 2019-01-31: this package does not exist on (cannot be installed on) Debian 10, SEE #1437
state: present
when: internet_available and not is_raspbian
# 2019-02-02: Sugarizer with Node.js 10.x requires MongoDB 2.6+ so
# https://andyfelong.com/2017/08/mongodb-3-0-14-for-raspbian-stretch/ is
# being used on Raspbian, all I found! (Raspbian's apt pkg is MongoDB 2.4.14)
@ -18,86 +10,105 @@
# CLARIF: mongodb_stretch_3_0_14_core.zip IS IN FACT 3.0.14 (core) BUT...
# mongodb_stretch_3_0_14_tools.zip IS REALLY 3.0.15 (tools)
- name: Create dir /tmp/mongodb-3.0.1x (raspbian)
file:
path: /tmp/mongodb-3.0.1x
state: directory
when: internet_available and is_raspbian
- block:
- name: Create dir /tmp/mongodb-3.0.1x (aarch32)
file:
path: /tmp/mongodb-3.0.1x
state: directory
- name: Download & unzip 20MB http://download.iiab.io/packages/mongodb_stretch_3_0_14_core.zip to /tmp/mongodb-3.0.1x (raspbian)
unarchive:
remote_src: yes
src: "{{ iiab_download_url }}/mongodb_stretch_3_0_14_core.zip"
dest: /tmp/mongodb-3.0.1x
when: internet_available and is_raspbian
- 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"
dest: /tmp/mongodb-3.0.1x
- name: Install (move) its 3 CORE binaries from /tmp/mongodb-3.0.1x/core to /usr/bin (raspbian)
shell: mv /tmp/mongodb-3.0.1x/core/* /usr/bin
when: internet_available and is_raspbian
- name: Install (move) its 3 CORE binaries from /tmp/mongodb-3.0.1x/core to /usr/bin (aarch32)
shell: mv /tmp/mongodb-3.0.1x/core/* /usr/bin
- name: Download & unzip 15MB http://download.iiab.io/packages/mongodb_stretch_3_0_14_tools.zip [IN FACT THIS ONE'S 3.0.15] to /tmp/mongodb-3.0.1x (raspbian)
unarchive:
remote_src: yes
src: "{{ iiab_download_url }}/mongodb_stretch_3_0_14_tools.zip"
dest: /tmp/mongodb-3.0.1x
when: internet_available and is_raspbian
- name: Download & unzip 15MB http://download.iiab.io/packages/mongodb_stretch_3_0_14_tools.zip [IN FACT THIS ONE'S 3.0.15] to /tmp/mongodb-3.0.1x (aarch32)
unarchive:
remote_src: yes
src: "{{ iiab_download_url }}/mongodb_stretch_3_0_14_tools.zip"
dest: /tmp/mongodb-3.0.1x
- name: Install (move) its 9 TOOLS binaries from /opt/iiab/downloads/mongodb-3.0.1x/tools to /usr/bin (raspbian)
shell: mv /tmp/mongodb-3.0.1x/tools/* /usr/bin
when: internet_available and is_raspbian
- name: Install (move) its 9 TOOLS binaries from /opt/iiab/downloads/mongodb-3.0.1x/tools to /usr/bin (aarch32)
shell: mv /tmp/mongodb-3.0.1x/tools/* /usr/bin
# OLD WAY / MUCH SLOWER: had put unnec duplicate copies in /opt/iiab/downloads/mongodb-3.0.1x
#
#- name: Create dir /opt/iiab/downloads/mongodb-3.0.1x (raspbian)
# file:
# path: "{{ downloads_dir }}/mongodb-3.0.1x"
# state: directory
# when: internet_available and is_raspbian
#
#- name: Download & unzip MongoDB 3.0.14's 3 core binaries to /opt/iiab/downloads/mongodb-3.0.1x (raspbian)
# unarchive:
# remote_src: yes
# src: "{{ iiab_download_url }}/mongodb_stretch_3_0_14_core.zip"
# dest: "{{ downloads_dir }}/mongodb-3.0.1x"
# when: internet_available and is_raspbian
#
#- name: Install (copy) 3 binaries from /opt/iiab/downloads/mongodb-3.0.1x/core to /usr/bin (raspbian)
# copy:
# src: "{{ item }}"
# dest: /usr/bin
# with_fileglob:
# - "{{ downloads_dir }}/mongodb-3.0.1x/core/*"
# when: internet_available and is_raspbian
#
#- name: Download & unzip MongoDB 3.0.15's 9 tools binaries to /opt/iiab/downloads/mongodb-3.0.1x (raspbian)
# unarchive:
# remote_src: yes
# src: "{{ iiab_download_url }}/mongodb_stretch_3_0_14_tools.zip"
# dest: "{{ downloads_dir }}/mongodb-3.0.1x"
# when: internet_available and is_raspbian
#
#- name: Install (copy) 9 binaries from /opt/iiab/downloads/mongodb-3.0.1x/tools to /usr/bin (raspbian)
# copy:
# src: "{{ item }}"
# dest: /usr/bin
# with_fileglob:
# - "{{ downloads_dir }}/mongodb-3.0.1x/tools/*"
# when: internet_available and is_raspbian
- name: Create Linux group mongodb (aarch32)
group:
name: mongodb
state: present
- name: Create Linux group mongodb (raspbian)
group:
name: mongodb
state: present
when: is_raspbian | bool
- name: Create Linux user mongodb (aarch32)
user:
name: mongodb
group: mongodb # primary group
groups: mongodb
home: /var/lib/mongodb
shell: /usr/sbin/nologin
- name: Create Linux user mongodb (raspbian)
user:
name: mongodb
group: mongodb # primary group
groups: mongodb
home: /var/lib/mongodb
shell: /usr/sbin/nologin
when: is_raspbian | bool
- name: Install /etc/mongod.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
# end block
when: not (ansible_architecture == "amd64" 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.
- block:
- name: Add mongodb.org signing key (only 64-bit support available)
shell: wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -
args:
warn: false
- name: Add mongodb repo for Debian 10 (only amd64 support available)
apt_repository:
repo: deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main
state: present
filename: mongodb-org
when: is_debian_10 and (ansible_architecture == "amd64")
# Debian 10 aarch64 might work below but is blocked in main.yml
- name: Add mongodb repo for Ubuntu 18 64bit or Raspbian-aarch64
apt_repository:
repo: deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse
state: present
filename: mongodb-org
when: (ansible_architecture == "aarch64" and is_raspbian_10) or is_ubuntu_18
- name: Add mongodb repo for Ubuntu 20 64bit
apt_repository:
repo: deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse
state: present
filename: mongodb-org
when: is_ubuntu_20 and (ansible_architecture == "aarch64" or ansible_architecture == "amd64")
- name: "Install packages: mongodb-org, mongodb-org-server"
package:
name:
- mongodb-org
- mongodb-org-server
state: present
- name: Change the mongodb port to 27018
lineinfile:
path: /etc/mongod.conf
regexp: 'port: 27017'
backrefs: yes
line: ' port: 27018'
# end block
when: (ansible_architecture == "aarch64") or (ansible_architecture == "amd64")
# 2. CONFIGURE MongoDB FOR IIAB
@ -114,7 +125,7 @@
- /var/log/mongodb
- "{{ mongodb_db_path }}" # i.e. /library/dbdata/mongodb/
- name: Install /etc/mongod.conf, mongodb.service, /usr/bin/iiab-mongodb-repair-if-no-lock from templates
- name: Install mongodb.service, /usr/bin/iiab-mongodb-repair-if-no-lock from templates
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
@ -122,10 +133,17 @@
group: root
mode: "{{ item.mode }}"
with_items:
- { src: 'mongod.conf.j2', dest: "{{ mongodb_conf }}", mode: '0644' } # i.e. /etc/mongod.conf
- { 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
systemd:
name: mongodb
daemon_reload: yes
enabled: no
state: restarted
# 3. RECORD MongoDB AS INSTALLED

View file

@ -31,24 +31,38 @@
- debug:
var: is_raspbian
- name: EXIT 'mongodb' ROLE & CONTINUE, IF 'is_debian and not is_raspbian' i.e. TRUE DEBIAN (where MongoDB no longer exists)
# might be able to lift this once we know using bionic would work
- name: EXIT 'mongodb' ROLE & CONTINUE, IF 'is_debian_10 and aarch64 and not is_raspbian' i.e. TRUE DEBIAN with arch64
fail: # FORCE IT RED THIS ONCE!
msg: ATTEMPTED MongoDB INSTALLATION WITH (TRUE) DEBIAN, which is no longer supported. Nevertheless IIAB will continue (consider this a warning!)
when: is_debian and not is_raspbian
#when: (is_debian and not is_raspbian) and (not is_debian_8) and (not is_debian_9) # Test for Debian 10+
msg: ATTEMPTED MongoDB INSTALLATION WITH (TRUE) DEBIAN aarch64, which is not supported upstream. Nevertheless IIAB will continue (consider this a warning!)
when: (ansible_architecture == "aarch64") and is_debian_10 and not is_raspbian
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: Install/Enable/Disable/Record MongoDB (main2.yml) if is_raspbian or not is_debian, i.e. not True Debian
include_tasks: main2.yml
when: is_raspbian or not is_debian
- 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
# THE block: APPROACH BELOW WORKS JUST LIKE main2.yml ABOVE.
# BUT IT VISUALLY POLLUTES: MANY BLUE "skipping:" MESSAGES IN ANSIBLE'S OUTPUT.
#'mongodb' systemd service - started on demand by sugarizer
# Just recording that mongodb should be running
# - block: # ENTIRE BLOCK CONDITIONED ON 'when: is_raspbian or not is_debian'
#
# [MOVED TO main2.yml]
#
# when: is_raspbian or not is_debian # CONDITION FOR ENTIRE ABOVE block:
- name: Add 'mongodb' variable values to {{ iiab_ini_file }}
ini_file:
path: "{{ iiab_ini_file }}" # /etc/iiab/iiab.ini
section: mongodb
option: "{{ item.option }}"
value: "{{ item.value | string }}"
with_items:
- option: name
value: MongoDB
- option: description
value: '"MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling."'
- option: enabled
value: "{{ mongodb_enabled }}"

View file

@ -1,34 +0,0 @@
- 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
- name: Enable & Restart 'mongodb' systemd service if mongodb_enabled, incl daemon-reload (in case mongodb.service changed?)
systemd:
name: mongodb
daemon_reload: yes
enabled: yes
state: restarted
when: mongodb_enabled | bool
- name: Disable & Stop 'mongodb' service, if not mongodb_enabled
systemd:
name: mongodb
enabled: no
state: stopped
when: not mongodb_enabled
- name: Add 'mongodb' variable values to {{ iiab_ini_file }}
ini_file:
path: "{{ iiab_ini_file }}" # /etc/iiab/iiab.ini
section: mongodb
option: "{{ item.option }}"
value: "{{ item.value | string }}"
with_items:
- option: name
value: MongoDB
- option: description
value: '"MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling."'
- option: enabled
value: "{{ mongodb_enabled }}"

View file

@ -22,12 +22,18 @@
# 3 stanzas moved up from install.yml, so Debian finishes "BIG" IIAB install:
# (WITH LOUD RED WARNINGS!)
- name: "Set 'mongodb_install: True' and 'mongodb_enabled: True'"
# If we got here sugarizer_install is True
- name: "Set 'mongodb_install: True'"
set_fact:
mongodb_install: True
mongodb_enabled: True
- name: MONGODB - run 'mongodb' role (attempt to install & enable MongoDB)
# auto started by sugarizer.service just to record that mongodb should be running
- name: "Set 'mongodb_enabled: True' when sugarizer_enabled"
set_fact:
mongodb_enabled: True
when: sugarizer_enabled
- name: MONGODB - run 'mongodb' role (attempt to install MongoDB)
include_role:
name: mongodb

View file

@ -18,27 +18,13 @@
when: sugarizer_enabled | bool # CONDITION FOR 2-STANZA block: ABOVE
- block: # 3 STANZAS BELOW, CONDITIONED ON 'when: not sugarizer_enabled'
# Stops 'sugarizer' but not 'mongodb'
- name: Disable & Stop 'sugarizer' systemd service, if not sugarizer_enabled
systemd:
name: sugarizer
enabled: no
state: stopped
# Disable & Stop 'mongodb' via 2 stanzas below
# (meta/main.yml did this in the past)
- name: "Set 'mongodb_enabled: False' if not sugarizer_enabled"
set_fact:
mongodb_enabled: False
- name: MONGODB - run 'mongodb' role, to Disable & Stop MongoDB, if not sugarizer_enabled
include_role:
name: mongodb
when: not sugarizer_enabled # CONDITION FOR 3-STANZA block: ABOVE
- 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