trfore.mongodb_install

Ansible Role: mongodb_install

CI CD

This role installs the community version of MongoDB, called mongodb-org, using the operating system's package manager or by downloading the server binaries. By default, it installs the latest release from version 4, but you can choose a newer version, such as mongodb_version: 6.0.16. Check the 'Tested Platforms and Versions' section for compatibility.

If you prefer to install the MongoDB server binaries directly (mongo, mongod, mongos), set mongodb_pkg_install: false. The role will then download the latest version from 4 or a newer version if specified. To use a local tar file, put it in your files directory and set these variables in your playbook:

  • mongodb_tar_src: mongodb-linux-x86_64-{DISTRO}-{VERSION}.tgz
  • mongodb_tar_src_remote: false

See the 'Example Playbooks' section for samples. This role does not configure the server; it uses default settings and minimal recommended system limits. For production, it is recommended to configure the server more thoroughly. For more information, visit: https://www.mongodb.com/docs/manual/administration/production-notes/

Install the Role

You can install this role using the Ansible Galaxy command line:

ansible-galaxy install trfore.mongodb_install

Or, include it in a requirements.yml file and install it with ansible-galaxy install -r requirements.yml, using:

---
roles:
  - trfore.mongodb_install

Tested Platforms and Versions

MongoDB Community 7.0.12

  • CentOS Stream 8 & 9
  • Debian 11 & 12
  • Ubuntu 20.04 & 22.04

MongoDB Community 6.0.16

  • CentOS Stream 8 & 9
  • Debian 10 & 11
  • Ubuntu 20.04 & 22.04

MongoDB Community 5.0.28

  • CentOS Stream 8
  • Debian 10 & 11
  • Ubuntu 20.04

MongoDB Community 4.4.29

  • CentOS Stream 8
  • Debian 10
  • Ubuntu 20.04

Requirements

  • ansible-core>=2.14.0

Dependencies

  • community.general.yum_versionlock (for CentOS & RHEL hosts)

    ansible-galaxy collection install community.general
    

Role Variables

Common Variables

Common variables with default values (see defaults/main.yml):

Variable Default Description Required
mongodb_pkg_install true Set to true to install MongoDB via package manager No
mongodb_version 4.4.29 Choose a version from MongoDB Community stable releases No
mongodb_version_maj Automatic Automatically extracts major version from mongodb_version Automatic
mongodb_version_maj_minor Automatic Automatically extracts major and minor from mongodb_version Automatic

Package Install Variables

defaults/main.yml:

Variable Default Description Required
mongodb_gpg_key URL URL of MongoDB GPG Key No
mongodb_pkg_hold true Set to true to hold the package version No
mongodb_pkg_hold_list MongoDB Packages List of installed MongoDB packages from mongodb-org No

Binary Install Variables

defaults/main.yml:

Variable Default Description Required
mongodb_tar_src URL URL or relative path to MongoDB binary tar file (installing from tar) No
mongodb_tar_src_remote true Set to true if downloading from URL (installing from tar) No
mongodb_path_exec /usr/bin Path where MongoDB binaries are located (installing from tar) No

Other OS Specific Variables

vars/debian.yml:

Variable Default Description Required
mongodb_path_db /var/lib/mongodb Path to the MongoDB database folder (install from tar) No
mongodb_path_log /var/log/mongodb Path to the MongoDB log folder (install from tar) No
mongodb_dependencies ["libcurl4","openssl","liblzma5"] Required packages for MongoDB (install from tar) No
mongodb_pkg_hold_list MongoDB Packages List of installed MongoDB packages from mongodb-org (pkg install) No

vars/redhat.yml and vars/redhat_mongo_v{4-6}.yml:

Variable Default Description Required
mongodb_path_db /var/lib/mongo Path to the MongoDB database folder (install from tar) No
mongodb_path_log /var/log/mongodb Path to the MongoDB log folder (install from tar) No
mongodb_dependencies ["libcurl-minimal","openssl","xz-libs"] Required packages for MongoDB (install from tar) No
mongodb_pkg_hold_list MongoDB Packages List of installed MongoDB packages from mongodb-org (pkg install) No

Example Playbooks

  • Install via package manager.
- hosts: servers
  become: true
  roles:
    - name: Install MongoDB
      role: trfore.mongodb_install
- hosts: servers
  become: true
  vars:
    mongodb_pkg_install: true
    mongodb_version: "6.0.16"
  roles:
    - name: Install MongoDB
      role: trfore.mongodb_install
  • Install from a tar file.
- hosts: servers
  become: true
  vars:
    mongodb_pkg_install: false
    mongodb_version: "6.0.16"
  roles:
    - name: Install MongoDB
      role: trfore.mongodb_install
  • Install from a local tar file.
- hosts: servers
  become: true
  vars:
    mongodb_pkg_install: false
    mongodb_tar_src: mongodb-linux-x86_64-debian10-4.4.29.tgz
    mongodb_tar_src_remote: false
  roles:
    - name: Install MongoDB
      role: trfore.mongodb_install

License

This Ansible role is licensed under MIT.

MongoDB Community is Server Side Public License software from MongoDB, Inc. More details: https://www.mongodb.com/licensing/server-side-public-license

Author Information

Taylor Fore (https://github.com/trfore)

Github Ansible Galaxy
ansible-role-jsvc trfore.jsvc
ansible-role-mongodb-install trfore.mongodb_install
ansible-role-omada-install trfore.omada_install

References

MongoDB

Informazioni sul progetto

Install MongoDB Community Edition on RedHat/CentOS and Debian/Ubuntu.

Installa
ansible-galaxy install trfore.mongodb_install
Licenza
mit
Download
946
Proprietario