From 975f66f2eebe9dadba04f275774d4ab83f74cf25 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 14:04:41 +0200 Subject: Adding upstream version 7.7.0+dfsg. Signed-off-by: Daniel Baumann --- .../mongodb/roles/mongodb_install/.yamllint | 33 ++++++++++++ .../mongodb/roles/mongodb_install/README.md | 34 ++++++++++++ .../mongodb_install/files/lock_mongodb_packages.sh | 24 +++++++++ .../mongodb/roles/mongodb_install/meta/main.yml | 57 ++++++++++++++++++++ .../mongodb_install/molecule/default/Dockerfile.j2 | 42 +++++++++++++++ .../mongodb_install/molecule/default/molecule.yml | 49 +++++++++++++++++ .../mongodb_install/molecule/default/playbook.yml | 7 +++ .../molecule/default/tests/test_default.py | 30 +++++++++++ .../molecule/mongodb_hold_packages/Dockerfile.j2 | 42 +++++++++++++++ .../molecule/mongodb_hold_packages/molecule.yml | 57 ++++++++++++++++++++ .../molecule/mongodb_hold_packages/playbook.yml | 8 +++ .../molecule/mongodb_hold_packages/prepare.yml | 12 +++++ .../mongodb_hold_packages/tests/test_default.py | 36 +++++++++++++ .../molecule/mongodb_nohold_packages/Dockerfile.j2 | 42 +++++++++++++++ .../molecule/mongodb_nohold_packages/molecule.yml | 57 ++++++++++++++++++++ .../molecule/mongodb_nohold_packages/playbook.yml | 8 +++ .../molecule/mongodb_nohold_packages/prepare.yml | 12 +++++ .../mongodb_nohold_packages/tests/test_default.py | 36 +++++++++++++ .../specific_mongodb_version/Dockerfile.j2 | 42 +++++++++++++++ .../molecule/specific_mongodb_version/molecule.yml | 45 ++++++++++++++++ .../molecule/specific_mongodb_version/playbook.yml | 9 ++++ .../specific_mongodb_version/tests/test_default.py | 36 +++++++++++++ .../molecule/virtualbox/molecule.yml | 54 +++++++++++++++++++ .../molecule/virtualbox/playbook.yml | 8 +++ .../molecule/virtualbox/prepare.yml | 45 ++++++++++++++++ .../molecule/virtualbox/tests/test_default.py | 31 +++++++++++ .../mongodb/roles/mongodb_install/tasks/main.yml | 61 ++++++++++++++++++++++ 27 files changed, 917 insertions(+) create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/.yamllint create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/README.md create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/files/lock_mongodb_packages.sh create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/meta/main.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/Dockerfile.j2 create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/molecule.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/playbook.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/tests/test_default.py create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/Dockerfile.j2 create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/molecule.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/playbook.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/prepare.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/tests/test_default.py create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/Dockerfile.j2 create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/molecule.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/playbook.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/prepare.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/tests/test_default.py create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/Dockerfile.j2 create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/molecule.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/playbook.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/tests/test_default.py create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/molecule.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/playbook.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/prepare.yml create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/tests/test_default.py create mode 100644 ansible_collections/community/mongodb/roles/mongodb_install/tasks/main.yml (limited to 'ansible_collections/community/mongodb/roles/mongodb_install') diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/.yamllint b/ansible_collections/community/mongodb/roles/mongodb_install/.yamllint new file mode 100644 index 000000000..882767605 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/.yamllint @@ -0,0 +1,33 @@ +--- +# Based on ansible-lint config +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + colons: + max-spaces-after: -1 + level: error + commas: + max-spaces-after: -1 + level: error + comments: disable + comments-indentation: disable + document-start: disable + empty-lines: + max: 3 + level: error + hyphens: + level: error + indentation: disable + key-duplicates: enable + line-length: disable + new-line-at-end-of-file: disable + new-lines: + type: unix + trailing-spaces: disable + truthy: disable diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/README.md b/ansible_collections/community/mongodb/roles/mongodb_install/README.md new file mode 100644 index 000000000..d16423688 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/README.md @@ -0,0 +1,34 @@ +mongodb_install +=============== + +Install MongoDB packages on Debian and RedHat based platforms. Installs the mongodb-org meta-package which then installs the following packages: mongodb-org-server, mongodb-org-shell, mongodb-org-mongos, mongodb-org-tools. + +Role Variables +-------------- + +specific_mongodb_version - Install a specific version of mongodb i.e. 4.4.1. The specified version must be available in the system repositories. By default this variable is undefined. +mongodb_hold_packages - Runs the lock_mongodb_packages.sh script to either lock mongodb-org packages at a specific version or to release the lock. Set to "HOLD" or "NOHOLD" as desired. No checks are made to see if the hold already exists or not. By default this variable is undefined and the script is not executed. The task is executed at the end and it is possible that packages could be upgraded before the lock is initially applied. + +Dependencies +------------ +mongodb_repository + +Example Playbook +---------------- + +```yaml + - hosts: servers + roles: + - mongodb_repository + - mongodb_install +``` + +License +------- + +BSD + +Author Information +------------------ + +Rhys Campbell (https://github.com/rhysmeister) diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/files/lock_mongodb_packages.sh b/ansible_collections/community/mongodb/roles/mongodb_install/files/lock_mongodb_packages.sh new file mode 100644 index 000000000..0c3e8e6f5 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/files/lock_mongodb_packages.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Hold mongodb-org packages on RHEL and Debian based systems + +set -e; +set -u; + +HOLD="$1"; +PACKAGE_NAME="mongodb-org*" + +if [[ "$HOLD" == "HOLD" ]]; then + if command -v yum &> /dev/null; then + yum versionlock "$PACKAGE_NAME" && touch /root/mongo_version_lock.success; + elif command -v apt-mark &> /dev/null; then + apt-mark hold "$PACKAGE_NAME" && touch /root/mongo_version_lock.success; + fi; +elif [[ "$HOLD" == "NOHOLD" ]]; then + if command -v yum &> /dev/null; then + yum versionlock delete "$PACKAGE_NAME" || true && rm -rf /root/mongo_version_lock.success; + elif command -v apt-mark &> /dev/null; then + apt-mark unhold "$PACKAGE_NAME" && rm -rf /root/mongo_version_lock.success; + fi; +else + echo "No action taken"; +fi; diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/meta/main.yml b/ansible_collections/community/mongodb/roles/mongodb_install/meta/main.yml new file mode 100644 index 000000000..ed4e3c4e7 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/meta/main.yml @@ -0,0 +1,57 @@ +--- +galaxy_info: + author: Rhys Campbell + description: Install MongoDB packages on Debian and RedHat based platforms. + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: GPLv3 + + min_ansible_version: 1.2 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # Optionally specify the branch Galaxy will use when accessing the GitHub + # repo for this role. During role install, if no tags are available, + # Galaxy will use this branch. During import Galaxy will access files on + # this branch. If Travis integration is configured, only notifications for this + # branch will be accepted. Otherwise, in all cases, the repo's default branch + # (usually master) will be used. + # github_branch: + + # + # platforms is a list of platforms, and each platform has a name and a list of versions. + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] +# List your role dependencies here, one per line. Be sure to remove the '[]' above, +# if you add dependencies to this list. diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/Dockerfile.j2 b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/Dockerfile.j2 new file mode 100644 index 000000000..77c8a3097 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/Dockerfile.j2 @@ -0,0 +1,42 @@ +# Molecule managed +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +{% if item.env is defined %} +{% for var, value in item.env.items() %} +{% if value %} +ENV {{ var }} {{ value }} +{% endif %} +{% endfor %} +{% endif %} + +{% if item.name == 'amazonlinux' or item.name == 'fedora' %} +RUN yum -y install systemd sudo python3 python3-setuptools python3-pip procps-ng; \ + cd /lib/systemd/system/sysinit.target.wants/ ; \ + for i in *; do [ $i = systemd-tmpfiles-setup.service ] || rm -f $i ; done ; \ + rm -f /lib/systemd/system/multi-user.target.wants/* ; \ + rm -f /etc/systemd/system/*.wants/* ; \ + rm -f /lib/systemd/system/local-fs.target.wants/* ; \ + rm -f /lib/systemd/system/sockets.target.wants/*udev* ; \ + rm -f /lib/systemd/system/sockets.target.wants/*initctl* ; \ + rm -f /lib/systemd/system/basic.target.wants/* ; \ + rm -f /lib/systemd/system/anaconda.target.wants/* ; +{% elif item.name == 'ubuntu_22' %} +RUN apt-get update && apt-get install -y python3 python3-setuptools python3-pip sudo bash ca-certificates iproute2 systemd-sysv procps netbase && apt-get clean; +{% else %} +# Add systemd-sysv package for Debian to get systemd working (and procps for sysctl) and netbase for firewalld +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 python3-setuptools python3-pip sudo bash ca-certificates iproute2 systemd-sysv procps netbase && apt-get clean; \ + elif [ $(command -v dnf) ] && grep -q 'platform:el8' /etc/os-release ; then dnf makecache && dnf update -y && dnf --assumeyes install python3 python3-setuptools python3-pip sudo python3-devel bash procps-ng && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && rm -Rf /usr/share/doc && rm -Rf /usr/share/man && dnf clean all && cp /bin/true /sbin/agetty; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python3 python3-setuptools python3-pip sudo python*-dnf bash iproute procps-ng && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python3 python3-setuptools python3-pip sudo yum-plugin-ovl bash iproute procps-ng && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python3 python3-setuptools python3-pip sudo bash python-xml iproute2 && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python3 python3-setuptools python3-pip sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python3 python3-setuptools python3-pip sudo bash ca-certificates iproute2 && xbps-remove -O; fi +{% endif %} +# TODO - Is this needed? Probably not +{% if item.name == 'debian_bullseye' %} +RUN apt install -y python3 python3-setuptools python3-pip +{% endif %} \ No newline at end of file diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/molecule.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/molecule.yml new file mode 100644 index 000000000..5258056e7 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/molecule.yml @@ -0,0 +1,49 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint + options: + config-data: + line-length: disable +platforms: + - name: almalinux_8 + image: almalinux:8 + - name: ubuntu_18 + image: ubuntu:18.04 + privileged: yes + command: "/sbin/init" + - name: ubuntu_22 + image: ubuntu:22.04 + privileged: yes + command: "/sbin/init" + - name: debian_bullseye + image: debian:bullseye + privileged: yes + command: "/sbin/init" + - name: fedora + image: fedora:37 +provisioner: + name: ansible + lint: + name: ansible-lint + enabled: false + inventory: + host_vars: + debian_bullseye: + ansible_python_interpreter: /usr/bin/python3 + fedora: # suitable for fedora 37 + redhat: + rpm_key_key: "https://www.mongodb.org/static/pgp/server-{{ mongodb_version }}.asc" + yum_baseurl: "https://repo.mongodb.org/yum/redhat/9/mongodb-org/{{ mongodb_version }}/x86_64/" + yum_gpgkey: "https://www.mongodb.org/static/pgp/server-{{ mongodb_version }}.asc" + yum_gpgcheck: true + yum_description: "Official MongoDB {{ mongodb_version }} yum repo" +verifier: + name: testinfra + lint: + name: flake8 + options: + ignore: 'E501' diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/playbook.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/playbook.yml new file mode 100644 index 000000000..cfcf732be --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/playbook.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + roles: + - role: mongodb_repository + tags: molecule-idempotence-notest + - role: mongodb_install diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/tests/test_default.py b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/tests/test_default.py new file mode 100644 index 000000000..08024e35b --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/default/tests/test_default.py @@ -0,0 +1,30 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE'] +).get_hosts('all') + + +def test_mongod_available(host): + cmd = host.run("mongod --version") + assert cmd.rc == 0 + assert "db version" in cmd.stdout + + +def test_mongo_available(host): + cmd = host.run("mongosh --version") + assert cmd.rc == 0 + + +def test_mongos_available(host): + cmd = host.run("mongos --version") + assert cmd.rc == 0 + assert "mongos version" in cmd.stdout + + +def test_mongodump_available(host): + cmd = host.run("mongodump --version") + assert cmd.rc == 0 + assert "mongodump version" in cmd.stdout diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/Dockerfile.j2 b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/Dockerfile.j2 new file mode 100644 index 000000000..77c8a3097 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/Dockerfile.j2 @@ -0,0 +1,42 @@ +# Molecule managed +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +{% if item.env is defined %} +{% for var, value in item.env.items() %} +{% if value %} +ENV {{ var }} {{ value }} +{% endif %} +{% endfor %} +{% endif %} + +{% if item.name == 'amazonlinux' or item.name == 'fedora' %} +RUN yum -y install systemd sudo python3 python3-setuptools python3-pip procps-ng; \ + cd /lib/systemd/system/sysinit.target.wants/ ; \ + for i in *; do [ $i = systemd-tmpfiles-setup.service ] || rm -f $i ; done ; \ + rm -f /lib/systemd/system/multi-user.target.wants/* ; \ + rm -f /etc/systemd/system/*.wants/* ; \ + rm -f /lib/systemd/system/local-fs.target.wants/* ; \ + rm -f /lib/systemd/system/sockets.target.wants/*udev* ; \ + rm -f /lib/systemd/system/sockets.target.wants/*initctl* ; \ + rm -f /lib/systemd/system/basic.target.wants/* ; \ + rm -f /lib/systemd/system/anaconda.target.wants/* ; +{% elif item.name == 'ubuntu_22' %} +RUN apt-get update && apt-get install -y python3 python3-setuptools python3-pip sudo bash ca-certificates iproute2 systemd-sysv procps netbase && apt-get clean; +{% else %} +# Add systemd-sysv package for Debian to get systemd working (and procps for sysctl) and netbase for firewalld +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 python3-setuptools python3-pip sudo bash ca-certificates iproute2 systemd-sysv procps netbase && apt-get clean; \ + elif [ $(command -v dnf) ] && grep -q 'platform:el8' /etc/os-release ; then dnf makecache && dnf update -y && dnf --assumeyes install python3 python3-setuptools python3-pip sudo python3-devel bash procps-ng && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && rm -Rf /usr/share/doc && rm -Rf /usr/share/man && dnf clean all && cp /bin/true /sbin/agetty; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python3 python3-setuptools python3-pip sudo python*-dnf bash iproute procps-ng && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python3 python3-setuptools python3-pip sudo yum-plugin-ovl bash iproute procps-ng && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python3 python3-setuptools python3-pip sudo bash python-xml iproute2 && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python3 python3-setuptools python3-pip sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python3 python3-setuptools python3-pip sudo bash ca-certificates iproute2 && xbps-remove -O; fi +{% endif %} +# TODO - Is this needed? Probably not +{% if item.name == 'debian_bullseye' %} +RUN apt install -y python3 python3-setuptools python3-pip +{% endif %} \ No newline at end of file diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/molecule.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/molecule.yml new file mode 100644 index 000000000..4266ee65b --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/molecule.yml @@ -0,0 +1,57 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint + options: + config-data: + line-length: disable +platforms: + - name: almalinux_8 + image: almalinux:8 + - name: fedora + image: fedora:37 + - name: ubuntu_18 + image: ubuntu:18.04 + - name: ubuntu_22 + image: ubuntu:22.04 + - name: debian_bullseye + image: debian:bullseye +provisioner: + name: ansible + lint: + name: ansible-lint + enabled: false + inventory: + host_vars: + debian_bullseye: + ansible_python_interpreter: /usr/bin/python3 + fedora: # suitable for fedora 37 + redhat: + yum_baseurl: "https://repo.mongodb.org/yum/redhat/9/mongodb-org/{{ mongodb_version }}/x86_64/" + rpm_key_key: "https://www.mongodb.org/static/pgp/server-{{ mongodb_version }}.asc" + yum_gpgkey: "https://www.mongodb.org/static/pgp/server-{{ mongodb_version }}.asc" + yum_gpgcheck: true + yum_description: "Official MongoDB {{ mongodb_version }} yum repo" +verifier: + name: testinfra + lint: + name: flake8 + options: + ignore: 'E501' +scenario: + test_sequence: + - dependency + - lint + - cleanup + - destroy + - syntax + - create + - prepare + - converge + - side_effect + - verify + - cleanup + - destroy diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/playbook.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/playbook.yml new file mode 100644 index 000000000..12ddc3a7d --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/playbook.yml @@ -0,0 +1,8 @@ +--- +- name: Converge + hosts: all + vars: + mongodb_hold_packages: "HOLD" + roles: + - role: mongodb_repository + - role: mongodb_install diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/prepare.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/prepare.yml new file mode 100644 index 000000000..8a94ca7eb --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/prepare.yml @@ -0,0 +1,12 @@ +--- +- name: Prepare + hosts: all + become: yes + + tasks: + + - name: Required packages + yum: + name: yum-plugin-versionlock + state: present + when: ansible_facts.os_family == "RedHat" diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/tests/test_default.py b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/tests/test_default.py new file mode 100644 index 000000000..381a5823a --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_hold_packages/tests/test_default.py @@ -0,0 +1,36 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE'] +).get_hosts('all') + + +def test_mongodb_lock_file(host): + f = host.file("/root/mongo_version_lock.success") + assert f.exists + + +def test_mongodb_packages_not_installed(host): + p = host.package("mongodb-org") + assert p.is_installed + p = host.package("mongodb-org-server") + assert p.is_installed + p = host.package("mongodb-mongosh") + assert p.is_installed + p = host.package("mongodb-org-mongos") + assert p.is_installed + p = host.package("mongodb-org-tools") + assert p.is_installed + + +def test_mongodb_packages_held(host): + test_apt = host.run("which apt-mark") + if test_apt.rc == 0: + c = "apt-mark showhold" + else: + c = "yum versionlock list" + cmd = host.run(c) + assert cmd.rc == 0 + assert 'mongodb-org' in cmd.stdout diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/Dockerfile.j2 b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/Dockerfile.j2 new file mode 100644 index 000000000..77c8a3097 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/Dockerfile.j2 @@ -0,0 +1,42 @@ +# Molecule managed +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +{% if item.env is defined %} +{% for var, value in item.env.items() %} +{% if value %} +ENV {{ var }} {{ value }} +{% endif %} +{% endfor %} +{% endif %} + +{% if item.name == 'amazonlinux' or item.name == 'fedora' %} +RUN yum -y install systemd sudo python3 python3-setuptools python3-pip procps-ng; \ + cd /lib/systemd/system/sysinit.target.wants/ ; \ + for i in *; do [ $i = systemd-tmpfiles-setup.service ] || rm -f $i ; done ; \ + rm -f /lib/systemd/system/multi-user.target.wants/* ; \ + rm -f /etc/systemd/system/*.wants/* ; \ + rm -f /lib/systemd/system/local-fs.target.wants/* ; \ + rm -f /lib/systemd/system/sockets.target.wants/*udev* ; \ + rm -f /lib/systemd/system/sockets.target.wants/*initctl* ; \ + rm -f /lib/systemd/system/basic.target.wants/* ; \ + rm -f /lib/systemd/system/anaconda.target.wants/* ; +{% elif item.name == 'ubuntu_22' %} +RUN apt-get update && apt-get install -y python3 python3-setuptools python3-pip sudo bash ca-certificates iproute2 systemd-sysv procps netbase && apt-get clean; +{% else %} +# Add systemd-sysv package for Debian to get systemd working (and procps for sysctl) and netbase for firewalld +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 python3-setuptools python3-pip sudo bash ca-certificates iproute2 systemd-sysv procps netbase && apt-get clean; \ + elif [ $(command -v dnf) ] && grep -q 'platform:el8' /etc/os-release ; then dnf makecache && dnf update -y && dnf --assumeyes install python3 python3-setuptools python3-pip sudo python3-devel bash procps-ng && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && rm -Rf /usr/share/doc && rm -Rf /usr/share/man && dnf clean all && cp /bin/true /sbin/agetty; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python3 python3-setuptools python3-pip sudo python*-dnf bash iproute procps-ng && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python3 python3-setuptools python3-pip sudo yum-plugin-ovl bash iproute procps-ng && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python3 python3-setuptools python3-pip sudo bash python-xml iproute2 && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python3 python3-setuptools python3-pip sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python3 python3-setuptools python3-pip sudo bash ca-certificates iproute2 && xbps-remove -O; fi +{% endif %} +# TODO - Is this needed? Probably not +{% if item.name == 'debian_bullseye' %} +RUN apt install -y python3 python3-setuptools python3-pip +{% endif %} \ No newline at end of file diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/molecule.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/molecule.yml new file mode 100644 index 000000000..4266ee65b --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/molecule.yml @@ -0,0 +1,57 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint + options: + config-data: + line-length: disable +platforms: + - name: almalinux_8 + image: almalinux:8 + - name: fedora + image: fedora:37 + - name: ubuntu_18 + image: ubuntu:18.04 + - name: ubuntu_22 + image: ubuntu:22.04 + - name: debian_bullseye + image: debian:bullseye +provisioner: + name: ansible + lint: + name: ansible-lint + enabled: false + inventory: + host_vars: + debian_bullseye: + ansible_python_interpreter: /usr/bin/python3 + fedora: # suitable for fedora 37 + redhat: + yum_baseurl: "https://repo.mongodb.org/yum/redhat/9/mongodb-org/{{ mongodb_version }}/x86_64/" + rpm_key_key: "https://www.mongodb.org/static/pgp/server-{{ mongodb_version }}.asc" + yum_gpgkey: "https://www.mongodb.org/static/pgp/server-{{ mongodb_version }}.asc" + yum_gpgcheck: true + yum_description: "Official MongoDB {{ mongodb_version }} yum repo" +verifier: + name: testinfra + lint: + name: flake8 + options: + ignore: 'E501' +scenario: + test_sequence: + - dependency + - lint + - cleanup + - destroy + - syntax + - create + - prepare + - converge + - side_effect + - verify + - cleanup + - destroy diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/playbook.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/playbook.yml new file mode 100644 index 000000000..e74a45b4d --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/playbook.yml @@ -0,0 +1,8 @@ +--- +- name: Converge + hosts: all + vars: + mongodb_hold_packages: "NOHOLD" + roles: + - role: mongodb_repository + - role: mongodb_install diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/prepare.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/prepare.yml new file mode 100644 index 000000000..325651e03 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/prepare.yml @@ -0,0 +1,12 @@ +--- +- name: Prepare + hosts: all + become: yes + + tasks: + + - name: Required packages + yum: + name: yum-plugin-versionlock + state: present + when: ansible_facts.os_family == "RedHat" \ No newline at end of file diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/tests/test_default.py b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/tests/test_default.py new file mode 100644 index 000000000..cd1fc5f79 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/mongodb_nohold_packages/tests/test_default.py @@ -0,0 +1,36 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE'] +).get_hosts('all') + + +def test_mongodb_lock_file(host): + f = host.file("/root/mongo_version_lock.success") + assert not f.exists + + +def test_mongodb_packages_installed(host): + p = host.package("mongodb-org") + assert p.is_installed + p = host.package("mongodb-org-server") + assert p.is_installed + p = host.package("mongodb-mongosh") + assert p.is_installed + p = host.package("mongodb-org-mongos") + assert p.is_installed + p = host.package("mongodb-org-tools") + assert p.is_installed + + +def test_mongodb_packages_held(host): + test_apt = host.run("which apt-mark") + if test_apt.rc == 0: + c = "apt-mark showhold" + else: + c = "yum versionlock list" + cmd = host.run(c) + assert cmd.rc == 0 + assert 'mongodb-org' not in cmd.stdout diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/Dockerfile.j2 b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/Dockerfile.j2 new file mode 100644 index 000000000..77c8a3097 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/Dockerfile.j2 @@ -0,0 +1,42 @@ +# Molecule managed +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +{% if item.env is defined %} +{% for var, value in item.env.items() %} +{% if value %} +ENV {{ var }} {{ value }} +{% endif %} +{% endfor %} +{% endif %} + +{% if item.name == 'amazonlinux' or item.name == 'fedora' %} +RUN yum -y install systemd sudo python3 python3-setuptools python3-pip procps-ng; \ + cd /lib/systemd/system/sysinit.target.wants/ ; \ + for i in *; do [ $i = systemd-tmpfiles-setup.service ] || rm -f $i ; done ; \ + rm -f /lib/systemd/system/multi-user.target.wants/* ; \ + rm -f /etc/systemd/system/*.wants/* ; \ + rm -f /lib/systemd/system/local-fs.target.wants/* ; \ + rm -f /lib/systemd/system/sockets.target.wants/*udev* ; \ + rm -f /lib/systemd/system/sockets.target.wants/*initctl* ; \ + rm -f /lib/systemd/system/basic.target.wants/* ; \ + rm -f /lib/systemd/system/anaconda.target.wants/* ; +{% elif item.name == 'ubuntu_22' %} +RUN apt-get update && apt-get install -y python3 python3-setuptools python3-pip sudo bash ca-certificates iproute2 systemd-sysv procps netbase && apt-get clean; +{% else %} +# Add systemd-sysv package for Debian to get systemd working (and procps for sysctl) and netbase for firewalld +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 python3-setuptools python3-pip sudo bash ca-certificates iproute2 systemd-sysv procps netbase && apt-get clean; \ + elif [ $(command -v dnf) ] && grep -q 'platform:el8' /etc/os-release ; then dnf makecache && dnf update -y && dnf --assumeyes install python3 python3-setuptools python3-pip sudo python3-devel bash procps-ng && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && rm -Rf /usr/share/doc && rm -Rf /usr/share/man && dnf clean all && cp /bin/true /sbin/agetty; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python3 python3-setuptools python3-pip sudo python*-dnf bash iproute procps-ng && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python3 python3-setuptools python3-pip sudo yum-plugin-ovl bash iproute procps-ng && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python3 python3-setuptools python3-pip sudo bash python-xml iproute2 && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python3 python3-setuptools python3-pip sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python3 python3-setuptools python3-pip sudo bash ca-certificates iproute2 && xbps-remove -O; fi +{% endif %} +# TODO - Is this needed? Probably not +{% if item.name == 'debian_bullseye' %} +RUN apt install -y python3 python3-setuptools python3-pip +{% endif %} \ No newline at end of file diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/molecule.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/molecule.yml new file mode 100644 index 000000000..3fdeb9123 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/molecule.yml @@ -0,0 +1,45 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint + options: + config-data: + line-length: disable +platforms: + #- name: almalinux_8 + # image: almalinux:8 yum seems broken for wildcard/version install for AL8 + #- name: fedora + # image: fedora:37 ditto + - name: centos7 + image: centos:7 # Just here while the above two are broken + - name: ubuntu_18 + image: ubuntu:18.04 + - name: ubuntu_22 + image: ubuntu:22.04 + - name: debian_bullseye + image: debian:bullseye +provisioner: + name: ansible + lint: + name: ansible-lint + enabled: false + inventory: + host_vars: + debian_bullseye: + ansible_python_interpreter: /usr/bin/python3 + fedora: # suitable for fedora 37 + redhat: + yum_baseurl: "https://repo.mongodb.org/yum/redhat/9/mongodb-org/{{ mongodb_version }}/x86_64/" + rpm_key_key: "https://www.mongodb.org/static/pgp/server-{{ mongodb_version }}.asc" + yum_gpgkey: "https://www.mongodb.org/static/pgp/server-{{ mongodb_version }}.asc" + yum_gpgcheck: true + yum_description: "Official MongoDB {{ mongodb_version }} yum repo" +verifier: + name: testinfra + lint: + name: flake8 + options: + ignore: 'E501' diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/playbook.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/playbook.yml new file mode 100644 index 000000000..9008b5f1e --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/playbook.yml @@ -0,0 +1,9 @@ +--- +- name: Converge + hosts: all + vars: + specific_mongodb_version: "6.0.3" + roles: + - role: mongodb_repository + mongodb_version: "6.0" + - role: mongodb_install diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/tests/test_default.py b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/tests/test_default.py new file mode 100644 index 000000000..b18055ed1 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/specific_mongodb_version/tests/test_default.py @@ -0,0 +1,36 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE'] +).get_hosts('all') + + +def test_mongod_available(host): + cmd = host.run("mongod --version") + assert cmd.rc == 0 + assert "db version" in cmd.stdout + + +def test_mongo_available(host): + cmd = host.run("mongosh --version") + assert cmd.rc == 0 + + +def test_mongos_available(host): + cmd = host.run("mongos --version") + assert cmd.rc == 0 + assert "mongos version" in cmd.stdout + + +def test_mongodump_available(host): + cmd = host.run("mongodump --version") + assert cmd.rc == 0 + assert "mongodump version" in cmd.stdout + + +def test_specific_mongodb_version(host): + cmd = host.run("mongod --version") + assert cmd.rc == 0 + assert "6.0.3" in cmd.stdout diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/molecule.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/molecule.yml new file mode 100644 index 000000000..14d29680a --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/molecule.yml @@ -0,0 +1,54 @@ +--- +dependency: + name: galaxy +driver: + name: vagrant + provider: + name: virtualbox +lint: + name: yamllint + options: + config-data: + line-length: disable +platforms: + - name: centos-7 + box: centos/7 + interfaces: + - network_name: private_network + type: dhcp + auto_config: true + - name: ubuntu-16 + box: ubuntu/xenial64 + interfaces: + - network_name: private_network + type: dhcp + auto_config: true + - name: ubuntu-18 + box: ubuntu/bionic64 + interfaces: + - network_name: private_network + type: dhcp + auto_config: true + - name: debian-buster + box: debian/buster64 + interfaces: + - network_name: private_network + type: dhcp + auto_config: true + - name: debian-stretch + box: debian/contrib-stretch64 # Standard debian/stretch64 had issues: Unable to locate package linux-headers-4.9.0-9-amd64 + interfaces: + - network_name: private_network + type: dhcp + auto_config: true +provisioner: + name: ansible + lint: + name: ansible-lint + enabled: false +verifier: + name: testinfra + lint: + name: flake8 + options: + ignore: 'E501' diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/playbook.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/playbook.yml new file mode 100644 index 000000000..1b64ffc53 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/playbook.yml @@ -0,0 +1,8 @@ +--- +- name: Converge + hosts: all + become: yes + roles: + - role: mongodb_repository + tags: molecule-idempotence-notest + - role: mongodb_install diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/prepare.yml b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/prepare.yml new file mode 100644 index 000000000..f7aef1aaf --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/prepare.yml @@ -0,0 +1,45 @@ +--- +- name: Prepare + hosts: all + become: yes + vars: + avahi_packages_redhat: + - "avahi" + - "nss-mdns" + avahi_packages_debian: + - "avahi-daemon" + - "avahi-discover" + - "libnss-mdns" + tasks: + + - name: Ensure epel is available + yum: + name: epel-release + state: present + when: + - ansible_os_family == "RedHat" + - ansible_distribution != "Fedora" + + - name: Install avahi packages + package: + name: "{{ avahi_packages_redhat }}" + state: present + when: ansible_os_family == "RedHat" + + - name: Install avahi packages + package: + name: "{{ avahi_packages_debian }}" + state: present + when: ansible_os_family == "Debian" + + # debian-stretch seems to require a reboot for avahi-daemon to run + - name: Reboot host + reboot: + + - name: Ensure services are started + service: + name: "{{ item }}" + state: started + with_items: + #- dbus + - avahi-daemon diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/tests/test_default.py b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/tests/test_default.py new file mode 100644 index 000000000..b8a23ad49 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/molecule/virtualbox/tests/test_default.py @@ -0,0 +1,31 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE'] +).get_hosts('all') + + +def test_mongod_available(host): + cmd = host.run("mongod --version") + assert cmd.rc == 0 + assert "db version" in cmd.stdout + + +def test_mongo_available(host): + cmd = host.run("mongo --version") + assert cmd.rc == 0 + assert "MongoDB shell version" in cmd.stdout + + +def test_mongos_available(host): + cmd = host.run("mongos --version") + assert cmd.rc == 0 + assert "mongos version" in cmd.stdout + + +def test_mongodump_available(host): + cmd = host.run("mongodump --version") + assert cmd.rc == 0 + assert "mongodump version" in cmd.stdout diff --git a/ansible_collections/community/mongodb/roles/mongodb_install/tasks/main.yml b/ansible_collections/community/mongodb/roles/mongodb_install/tasks/main.yml new file mode 100644 index 000000000..d43174fd3 --- /dev/null +++ b/ansible_collections/community/mongodb/roles/mongodb_install/tasks/main.yml @@ -0,0 +1,61 @@ +--- +# tasks file for mongodb_install +- name: Install MongoDB Packages + package: + name: mongodb-org + state: present + when: specific_mongodb_version is not defined + register: _pkg + until: _pkg is succeeded + retries: 5 + tags: + - "mongodb" + - "setup" + - "pkg" + +- name: Install MongoDB Packages (Specific version) + package: + name: "mongodb-org*{{ specific_mongodb_version }}" + state: present + when: + - specific_mongodb_version is defined + - ansible_facts.os_family == "RedHat" + register: _pkg + until: _pkg is succeeded + retries: 5 + tags: + - "mongodb" + - "setup" + - "pkg" + +# apt silliness: +# In order to upgrade/downgrade to a specific version of mongodb-org, +# we must also specify version of mongodb-org deps. +# https://dba.stackexchange.com/questions/197336/how-to-install-specific-mongo-version-from-the-ppa +- name: Install MongoDB Packages (Specific version) + package: + name: + - "mongodb-org={{ specific_mongodb_version }}" + - "mongodb-org-server={{ specific_mongodb_version }}" + - "mongodb-mongosh" # mongosh package uses a new versioning number schema + - "mongodb-org-mongos={{ specific_mongodb_version }}" + - "mongodb-org-tools={{ specific_mongodb_version }}" + state: present + when: + - specific_mongodb_version is defined + - ansible_facts.os_family == "Debian" + register: _pkg + until: _pkg is succeeded + retries: 5 + tags: + - "mongodb" + - "setup" + - "pkg" + - "debian" + +- name: Manage package locks - {{ mongodb_hold_packages }} + script: lock_mongodb_packages.sh {{ mongodb_hold_packages }} + when: + - mongodb_hold_packages is defined + tags: + - "mongodb" -- cgit v1.2.3