2019-02-02 15:03:49 +00:00
|
|
|
# 1. INSTALL MongoDB PACKAGES OR BINARIES
|
|
|
|
|
|
|
|
# 2019-02-02: Sugarizer with Node.js 10.x requires MongoDB 2.6+ so
|
2020-05-21 17:00:01 +00:00
|
|
|
# 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)
|
2019-02-02 15:03:49 +00:00
|
|
|
#
|
|
|
|
# mongodb_stretch_3_0_14_core.zip (20M) & mongodb_stretch_3_0_14_tools.zip (15M)
|
|
|
|
# were backed up from andyfelong.com to http://download.iiab.io/packages/
|
|
|
|
#
|
|
|
|
# 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)
|
|
|
|
|
2020-08-25 21:41:14 +00:00
|
|
|
- block:
|
2020-08-26 20:08:07 +00:00
|
|
|
- name: Create dir /tmp/mongodb-3.0.1x (aarch32)
|
2020-08-25 21:41:14 +00:00
|
|
|
file:
|
|
|
|
path: /tmp/mongodb-3.0.1x
|
|
|
|
state: directory
|
|
|
|
|
2020-08-26 20:08:07 +00:00
|
|
|
- name: Download & unzip 20MB http://download.iiab.io/packages/mongodb_stretch_3_0_14_core.zip to /tmp/mongodb-3.0.1x (aarch32)
|
2020-08-25 21:41:14 +00:00
|
|
|
unarchive:
|
|
|
|
remote_src: yes
|
|
|
|
src: "{{ iiab_download_url }}/mongodb_stretch_3_0_14_core.zip"
|
|
|
|
dest: /tmp/mongodb-3.0.1x
|
|
|
|
|
2020-08-26 20:08:07 +00:00
|
|
|
- name: Install (move) its 3 CORE binaries from /tmp/mongodb-3.0.1x/core to /usr/bin (aarch32)
|
2020-08-25 21:41:14 +00:00
|
|
|
shell: mv /tmp/mongodb-3.0.1x/core/* /usr/bin
|
|
|
|
|
2020-08-26 20:08:07 +00:00
|
|
|
- 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)
|
2020-08-25 21:41:14 +00:00
|
|
|
unarchive:
|
|
|
|
remote_src: yes
|
|
|
|
src: "{{ iiab_download_url }}/mongodb_stretch_3_0_14_tools.zip"
|
|
|
|
dest: /tmp/mongodb-3.0.1x
|
|
|
|
|
2020-08-26 20:08:07 +00:00
|
|
|
- name: Install (move) its 9 TOOLS binaries from /opt/iiab/downloads/mongodb-3.0.1x/tools to /usr/bin (aarch32)
|
2020-08-25 21:41:14 +00:00
|
|
|
shell: mv /tmp/mongodb-3.0.1x/tools/* /usr/bin
|
|
|
|
|
2020-08-26 20:08:07 +00:00
|
|
|
- name: Create Linux group mongodb (aarch32)
|
2020-08-25 21:41:14 +00:00
|
|
|
group:
|
|
|
|
name: mongodb
|
|
|
|
state: present
|
|
|
|
|
2020-08-26 20:08:07 +00:00
|
|
|
- name: Create Linux user mongodb (aarch32)
|
2020-08-25 21:41:14 +00:00
|
|
|
user:
|
|
|
|
name: mongodb
|
|
|
|
group: mongodb # primary group
|
|
|
|
groups: mongodb
|
|
|
|
home: /var/lib/mongodb
|
|
|
|
shell: /usr/sbin/nologin
|
2020-08-25 22:02:52 +00:00
|
|
|
|
2020-08-26 20:08:07 +00:00
|
|
|
- name: Install /etc/mongod.conf from template (aarch32)
|
2020-08-26 01:30:39 +00:00
|
|
|
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
|
|
|
|
|
2020-08-25 22:02:52 +00:00
|
|
|
# end block
|
2020-08-29 00:37:01 +00:00
|
|
|
when: not (ansible_architecture == "x86_64" or ansible_architecture == "aarch64")
|
2020-09-02 01:22:06 +00:00
|
|
|
|
2020-08-26 20:08:07 +00:00
|
|
|
# 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.
|
2020-09-02 01:22:06 +00:00
|
|
|
|
2020-08-25 21:41:14 +00:00
|
|
|
- block:
|
2020-08-26 20:08:07 +00:00
|
|
|
- name: Add mongodb.org signing key (only 64-bit support available)
|
2020-08-25 21:41:14 +00:00
|
|
|
shell: wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -
|
2020-08-26 02:55:42 +00:00
|
|
|
args:
|
|
|
|
warn: false
|
2020-08-25 21:41:14 +00:00
|
|
|
|
2020-09-02 02:37:54 +00:00
|
|
|
- name: Use mongodb-org's Debian repo for Debian (only amd64 support available)
|
2020-08-25 21:41:14 +00:00
|
|
|
apt_repository:
|
2020-10-28 21:23:46 +00:00
|
|
|
# 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
|
2020-08-25 21:41:14 +00:00
|
|
|
state: present
|
|
|
|
filename: mongodb-org
|
2020-09-02 01:50:00 +00:00
|
|
|
when: is_debian and (ansible_architecture == "x86_64")
|
2020-08-25 21:41:14 +00:00
|
|
|
|
2020-08-26 20:08:07 +00:00
|
|
|
# Debian 10 aarch64 might work below but is blocked in main.yml
|
2020-09-01 11:00:32 +00:00
|
|
|
- name: Use mongodb-org's Ubuntu bionic repo for RaspOS-aarch64
|
2020-08-26 01:02:40 +00:00
|
|
|
apt_repository:
|
|
|
|
repo: deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse
|
|
|
|
state: present
|
|
|
|
filename: mongodb-org
|
2020-09-02 02:37:54 +00:00
|
|
|
when: is_raspbian and (ansible_architecture == "aarch64")
|
2020-08-26 01:02:40 +00:00
|
|
|
|
2020-09-02 01:22:06 +00:00
|
|
|
- name: Use mongodb-org's Ubuntu focal repo for Linux Mint - 64bit only
|
2020-08-25 21:41:14 +00:00
|
|
|
apt_repository:
|
2020-09-01 11:00:32 +00:00
|
|
|
repo: deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse
|
2020-08-25 21:41:14 +00:00
|
|
|
state: present
|
|
|
|
filename: mongodb-org
|
2020-10-16 20:46:19 +00:00
|
|
|
when: is_linuxmint
|
2020-09-01 10:13:20 +00:00
|
|
|
|
2020-09-02 01:22:06 +00:00
|
|
|
- name: Use mongodb-org's Ubuntu repo for all non-Mint Ubuntu - 64bit only
|
2020-09-01 10:13:20 +00:00
|
|
|
apt_repository:
|
2020-10-27 16:37:29 +00:00
|
|
|
# 2020-10-27: https://repo.mongodb.org/apt/ubuntu/dists/ supports only
|
|
|
|
# {focal 20.04, bionic 18.04, xenial 16.04, trusty 14.04, precise 12.04}
|
|
|
|
# so other Ubuntu's like groovy 20.10 need to revert to recent LTS repo:
|
|
|
|
repo: deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse
|
|
|
|
#repo: deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/4.4 multiverse
|
2020-09-01 10:13:20 +00:00
|
|
|
state: present
|
|
|
|
filename: mongodb-org
|
2020-09-02 01:22:06 +00:00
|
|
|
when: is_ubuntu and not is_linuxmint
|
2020-08-25 21:41:14 +00:00
|
|
|
|
|
|
|
- name: "Install packages: mongodb-org, mongodb-org-server"
|
|
|
|
package:
|
|
|
|
name:
|
|
|
|
- mongodb-org
|
|
|
|
- mongodb-org-server
|
|
|
|
state: present
|
2020-08-25 22:02:52 +00:00
|
|
|
|
2020-08-26 01:56:35 +00:00
|
|
|
- name: Change the mongodb port to 27018
|
|
|
|
lineinfile:
|
|
|
|
path: /etc/mongod.conf
|
2020-08-26 02:55:42 +00:00
|
|
|
regexp: 'port: 27017'
|
2020-08-26 02:17:53 +00:00
|
|
|
backrefs: yes
|
2020-08-26 01:56:35 +00:00
|
|
|
line: ' port: 27018'
|
|
|
|
|
2020-08-25 22:02:52 +00:00
|
|
|
# end block
|
2020-08-29 00:37:01 +00:00
|
|
|
when: (ansible_architecture == "aarch64") or (ansible_architecture == "x86_64")
|
2019-02-02 18:48:50 +00:00
|
|
|
|
|
|
|
|
2020-01-29 15:23:00 +00:00
|
|
|
# 2. CONFIGURE MongoDB FOR IIAB
|
2019-02-02 15:03:49 +00:00
|
|
|
|
2019-02-02 19:38:52 +00:00
|
|
|
- name: 'Create 3 dirs for MongoDB: /var/lib/mongodb, /var/log/mongodb, {{ mongodb_db_path }}'
|
2018-07-12 00:49:03 +00:00
|
|
|
file:
|
|
|
|
state: directory
|
2019-02-02 19:38:52 +00:00
|
|
|
path: "{{ item }}"
|
2018-07-12 00:49:03 +00:00
|
|
|
owner: mongodb
|
2019-02-02 19:38:52 +00:00
|
|
|
group: mongodb
|
2017-05-27 18:09:50 +00:00
|
|
|
with_items:
|
2019-02-02 19:38:52 +00:00
|
|
|
#- { path: '/var/run/mongodb' }
|
|
|
|
- /var/lib/mongodb
|
|
|
|
- /var/log/mongodb
|
|
|
|
- "{{ mongodb_db_path }}" # i.e. /library/dbdata/mongodb/
|
2017-05-27 18:09:50 +00:00
|
|
|
|
2020-08-26 01:30:39 +00:00
|
|
|
- name: Install mongodb.service, /usr/bin/iiab-mongodb-repair-if-no-lock from templates
|
2018-07-12 00:49:03 +00:00
|
|
|
template:
|
|
|
|
src: "{{ item.src }}"
|
|
|
|
dest: "{{ item.dest }}"
|
|
|
|
owner: root
|
|
|
|
group: root
|
2018-07-23 14:01:21 +00:00
|
|
|
mode: "{{ item.mode }}"
|
2017-05-27 18:09:50 +00:00
|
|
|
with_items:
|
2018-07-23 14:01:21 +00:00
|
|
|
- { 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' }
|
2018-07-22 15:01:31 +00:00
|
|
|
|
2020-08-26 14:12:57 +00:00
|
|
|
# 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
|
2020-01-29 15:23:00 +00:00
|
|
|
|
2020-09-02 01:22:06 +00:00
|
|
|
|
2020-01-30 09:00:00 +00:00
|
|
|
# 3. RECORD MongoDB AS INSTALLED
|
2020-01-29 15:23:00 +00:00
|
|
|
|
2020-01-30 09:00:00 +00:00
|
|
|
- name: "Set 'mongodb_installed: True'"
|
|
|
|
set_fact:
|
2020-01-29 16:43:59 +00:00
|
|
|
mongodb_installed: True
|
|
|
|
|
2020-01-12 23:15:33 +00:00
|
|
|
- name: "Add 'mongodb_installed: True' to {{ iiab_state_file }}"
|
2019-10-14 17:18:16 +00:00
|
|
|
lineinfile:
|
2020-02-04 00:54:04 +00:00
|
|
|
path: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
|
2019-10-14 17:18:16 +00:00
|
|
|
regexp: '^mongodb_installed'
|
|
|
|
line: 'mongodb_installed: True'
|