From fc23fabd3e47ec89a1b24a78209241b9352f038f Mon Sep 17 00:00:00 2001 From: Teodoro Cook Date: Sun, 14 Jan 2024 20:03:54 -0600 Subject: [PATCH] Add hostfile manage option flag (#32) --- .github/workflows/molecule.yml | 2 +- galaxy.yml | 2 +- molecule/install/molecule.yml | 114 ++++++++++++++++++++++++++------- molecule/offline/molecule.yml | 106 ++++++++++++++++++++++++------ molecule/online/molecule.yml | 106 ++++++++++++++++++++++++------ molecule/restart/molecule.yml | 106 ++++++++++++++++++++++++------ molecule/start/molecule.yml | 106 ++++++++++++++++++++++++------ molecule/stop/molecule.yml | 106 ++++++++++++++++++++++++------ molecule/update/molecule.yml | 106 ++++++++++++++++++++++++------ molecule/upgrade/molecule.yml | 100 ++++++++++++++++++++++++----- playbooks/config.yml | 10 +-- playbooks/mongos.yml | 24 +++++-- playbooks/offline.yml | 4 +- playbooks/online.yml | 4 +- playbooks/prepare.yml | 7 +- playbooks/restart.yml | 18 +++--- playbooks/shard.yml | 8 ++- playbooks/start.yml | 10 ++- playbooks/stop.yml | 10 ++- playbooks/update.yml | 18 +++--- playbooks/vars/main.yml | 15 +++-- poetry.lock | 93 ++++++++++++++++++++++++++- pyproject.toml | 1 + 23 files changed, 867 insertions(+), 209 deletions(-) diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml index 32f8fbd..fe58336 100644 --- a/.github/workflows/molecule.yml +++ b/.github/workflows/molecule.yml @@ -11,7 +11,7 @@ on: jobs: molecule: name: molecule - runs-on: libvirt + runs-on: ubuntu-latest strategy: matrix: scenario: diff --git a/galaxy.yml b/galaxy.yml index 0ff84c3..621173a 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: nephelaiio name: mongodb -version: 0.2.0 +version: 0.2.1 readme: README.md authors: - Ted Cook diff --git a/molecule/install/molecule.yml b/molecule/install/molecule.yml index 5f03f20..6edb836 100644 --- a/molecule/install/molecule.yml +++ b/molecule/install/molecule.yml @@ -5,74 +5,142 @@ dependency: role-file: requirements.yml requirements-file: requirements.yml driver: - name: default + name: docker platforms: - name: mongodb-install-mongos01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-install-mongos02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-install-config01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-install-config02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-install-config03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-install-shard01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-install-shard02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-install-shard03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb provisioner: name: ansible + config_options: + defaults: + callbacks_enabled: ansible.posix.profile_tasks playbooks: - create: ../common/create.yml prepare: ../common/prepare.yml converge: ../common/install.yml side_effect: ../common/install.yml verify: ../common/verify.yml - destroy: ../common/destroy.yml - cleanup: ../common/cleanup.yml - config_options: - defaults: - callbacks_enabled: ansible.posix.profile_tasks + inventory: + hosts: + all: + vars: + mongodb_hosts_manage: false verifier: name: ansible scenario: - prepare_sequence: - - prepare - converge_sequence: - - converge - destroy_sequence: - - destroy - cleanup_sequence: - - cleanup test_sequence: - dependency + - cleanup + - destroy - create - prepare - converge diff --git a/molecule/offline/molecule.yml b/molecule/offline/molecule.yml index 0f4e24b..440d777 100644 --- a/molecule/offline/molecule.yml +++ b/molecule/offline/molecule.yml @@ -5,69 +5,135 @@ dependency: role-file: requirements.yml requirements-file: requirements.yml driver: - name: default + name: docker platforms: - name: mongodb-offline-mongos01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-offline-mongos02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-offline-config01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-offline-config02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-offline-config03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-offline-shard01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-offline-shard02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-offline-shard03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb provisioner: name: ansible playbooks: - create: ../common/create.yml converge: ../common/offline.yml - destroy: ../common/destroy.yml - cleanup: ../common/cleanup.yml config_options: defaults: callbacks_enabled: ansible.posix.profile_tasks + inventory: + hosts: + all: + vars: + mongodb_hosts_manage: false verifier: name: ansible scenario: - prepare_sequence: - - prepare - converge_sequence: - - converge - destroy_sequence: - - destroy - cleanup_sequence: - - cleanup test_sequence: - dependency - create diff --git a/molecule/online/molecule.yml b/molecule/online/molecule.yml index b37b2b9..cdb0f61 100644 --- a/molecule/online/molecule.yml +++ b/molecule/online/molecule.yml @@ -5,71 +5,137 @@ dependency: role-file: requirements.yml requirements-file: requirements.yml driver: - name: default + name: docker platforms: - name: mongodb-online-mongos01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-online-mongos02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-online-config01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-online-config02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-online-config03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-online-shard01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-online-shard02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-online-shard03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb provisioner: name: ansible playbooks: - create: ../common/create.yml converge: ../common/offline.yml side_effect: ../common/online.yml verify: ../common/verify.yml - destroy: ../common/destroy.yml - cleanup: ../common/cleanup.yml config_options: defaults: callbacks_enabled: ansible.posix.profile_tasks + inventory: + hosts: + all: + vars: + mongodb_hosts_manage: false verifier: name: ansible scenario: - prepare_sequence: - - prepare - converge_sequence: - - converge - destroy_sequence: - - destroy - cleanup_sequence: - - cleanup test_sequence: - dependency - create diff --git a/molecule/restart/molecule.yml b/molecule/restart/molecule.yml index 98692d6..415b348 100644 --- a/molecule/restart/molecule.yml +++ b/molecule/restart/molecule.yml @@ -5,72 +5,138 @@ dependency: role-file: requirements.yml requirements-file: requirements.yml driver: - name: default + name: docker platforms: - name: mongodb-restart-mongos01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-restart-mongos02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-restart-config01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-restart-config02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-restart-config03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-restart-shard01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-restart-shard02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-restart-shard03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb provisioner: name: ansible playbooks: - create: ../common/create.yml prepare: ../common/prepare.yml converge: ../common/install.yml side_effect: ../common/restart.yml verify: ../common/verify.yml - destroy: ../common/destroy.yml - cleanup: ../common/cleanup.yml config_options: defaults: callbacks_enabled: ansible.posix.profile_tasks + inventory: + hosts: + all: + vars: + mongodb_hosts_manage: false verifier: name: ansible scenario: - prepare_sequence: - - prepare - converge_sequence: - - converge - destroy_sequence: - - destroy - cleanup_sequence: - - cleanup test_sequence: - dependency - create diff --git a/molecule/start/molecule.yml b/molecule/start/molecule.yml index 6935f4a..c45c4b4 100644 --- a/molecule/start/molecule.yml +++ b/molecule/start/molecule.yml @@ -5,70 +5,136 @@ dependency: role-file: requirements.yml requirements-file: requirements.yml driver: - name: default + name: docker platforms: - name: mongodb-start-mongos01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-start-mongos02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-start-config01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-start-config02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-start-config03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-start-shard01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-start-shard02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-start-shard03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb provisioner: name: ansible playbooks: - create: ../common/create.yml converge: ../common/start.yml verify: ../common/start.yml - destroy: ../common/destroy.yml - cleanup: ../common/cleanup.yml config_options: defaults: callbacks_enabled: ansible.posix.profile_tasks + inventory: + hosts: + all: + vars: + mongodb_hosts_manage: false verifier: name: ansible scenario: - prepare_sequence: - - prepare - converge_sequence: - - converge - destroy_sequence: - - destroy - cleanup_sequence: - - cleanup test_sequence: - dependency - create diff --git a/molecule/stop/molecule.yml b/molecule/stop/molecule.yml index 86b6dad..ece0313 100644 --- a/molecule/stop/molecule.yml +++ b/molecule/stop/molecule.yml @@ -5,69 +5,135 @@ dependency: role-file: requirements.yml requirements-file: requirements.yml driver: - name: default + name: docker platforms: - name: mongodb-stop-mongos01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-stop-mongos02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-stop-config01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-stop-config02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-stop-config03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-stop-shard01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-stop-shard02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-stop-shard03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb provisioner: name: ansible playbooks: - create: ../common/create.yml converge: ../common/stop.yml - destroy: ../common/destroy.yml - cleanup: ../common/cleanup.yml config_options: defaults: callbacks_enabled: ansible.posix.profile_tasks + inventory: + hosts: + all: + vars: + mongodb_hosts_manage: false verifier: name: ansible scenario: - prepare_sequence: - - prepare - converge_sequence: - - converge - destroy_sequence: - - destroy - cleanup_sequence: - - cleanup test_sequence: - dependency - create diff --git a/molecule/update/molecule.yml b/molecule/update/molecule.yml index 855a6b5..236be54 100644 --- a/molecule/update/molecule.yml +++ b/molecule/update/molecule.yml @@ -5,72 +5,138 @@ dependency: role-file: requirements.yml requirements-file: requirements.yml driver: - name: default + name: docker platforms: - name: mongodb-update-mongos01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-update-mongos02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-update-config01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-update-config02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-update-config03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-update-shard01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-update-shard02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-update-shard03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb provisioner: name: ansible playbooks: - create: ../common/create.yml prepare: ../common/prepare.yml converge: ../common/install.yml side_effect: ../common/restart.yml verify: ../common/verify.yml - destroy: ../common/destroy.yml - cleanup: ../common/cleanup.yml config_options: defaults: callbacks_enabled: ansible.posix.profile_tasks + inventory: + hosts: + all: + vars: + mongodb_hosts_manage: false verifier: name: ansible scenario: - prepare_sequence: - - prepare - converge_sequence: - - converge - destroy_sequence: - - destroy - cleanup_sequence: - - cleanup test_sequence: - dependency - create diff --git a/molecule/upgrade/molecule.yml b/molecule/upgrade/molecule.yml index 6da9758..8ed4142 100644 --- a/molecule/upgrade/molecule.yml +++ b/molecule/upgrade/molecule.yml @@ -5,56 +5,125 @@ dependency: role-file: requirements.yml requirements-file: requirements.yml driver: - name: default + name: docker platforms: - name: mongodb-upgrade-mongos01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-upgrade-mongos02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_mongos - mongodb - name: mongodb-upgrade-config01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-upgrade-config02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-upgrade-config03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_config - mongodb - name: mongodb-upgrade-shard01 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-upgrade-shard02 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb - name: mongodb-upgrade-shard03 - image: "${MOLECULE_KVM_IMAGE}" + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt groups: - mongodb_shard1 - mongodb provisioner: name: ansible playbooks: - create: ../common/create.yml prepare: ../common/prepare.yml verify: ../common/verify.yml - destroy: ../common/destroy.yml - cleanup: ../common/cleanup.yml config_options: defaults: callbacks_enabled: ansible.posix.profile_tasks @@ -69,6 +138,9 @@ provisioner: - mongodb-org-server - mongodb-org-mongos - mongodb-mongosh + - python3-pymongo + - python3-gnupg + mongodb_hosts_manage: false verifier: name: ansible scenario: @@ -76,10 +148,6 @@ scenario: - prepare converge_sequence: - converge - destroy_sequence: - - destroy - cleanup_sequence: - - cleanup test_sequence: - dependency - create diff --git a/playbooks/config.yml b/playbooks/config.yml index e636640..7b405cf 100644 --- a/playbooks/config.yml +++ b/playbooks/config.yml @@ -1,6 +1,6 @@ --- - name: Query config replicaset member status - hosts: "{{ mongodb_config | default('mongodb_config') }}" + hosts: "{{ __mongodb_config }}" vars_files: - main.yml tasks: @@ -11,7 +11,7 @@ ansible.builtin.group_by: key: "mongodb_config_{{ _status }}" vars: - _service: "{{ mongodb_service_name }}.service" + _service: "{{ _mongodb_service_name }}.service" _deployed: "{{ _service in services }}" _stopped: "{{ _deployed and services[_service].state != 'running' }}" _inactive: "{{ (not _deployed) or _stopped }}" @@ -19,12 +19,14 @@ - name: Set replicaset facts ansible.builtin.set_fact: - mongodb_replicaset_members: "{{ mongodb_members | map(_filter, '%s:' + mongodb_port) | list }}" + mongodb_replicaset_members: "{{ _mongodb_members | map(_filter, '%s:' + _mongodb_port) | list }}" mongodb_replicaset_name: "{{ mongos_replicaset_config_name | default('config') }}" mongodb_sharding_role: configsvr vars: _filter: "nephelaiio.plugins.map_format" - mongodb_members: "{{ groups[mongodb_config | default('mongodb_config')] }}" + _mongodb_hosts: "{{ groups[__mongodb_config] }}" + _mongodb_addrs: "{{ _mongodb_hosts | map('extract', hostvars, __mongodb_address_attrs) | list }}" + _mongodb_members: "{{ _mongodb_hosts if _mongodb_hosts_manage else _mongodb_addrs }}" - name: Deploy new config replicaset members diff --git a/playbooks/mongos.yml b/playbooks/mongos.yml index e8dfcba..3cd378f 100644 --- a/playbooks/mongos.yml +++ b/playbooks/mongos.yml @@ -1,19 +1,31 @@ --- +- name: Gather cluster facts + hosts: + - "{{ __mongodb_config }}" + - "{{ __mongodb_shard1 }}" + - "{{ __mongodb_mongos }}" + become: true + vars_files: + - main.yml + + - name: Deploy MongoDB Mongos servers - hosts: "{{ mongodb_mongos | default('mongodb_mongos') }}" + hosts: "{{ __mongodb_mongos }}" become: true serial: 1 vars_files: - main.yml vars: - mongos_replicaset_config_members: "{{ groups[mongodb_config | default('mongodb_config')] }}" + _config_hosts: "{{ groups[__mongodb_config] }}" + _config_addrs: "{{ _config_hosts | map('extract', hostvars, __mongodb_address_attrs) | list }}" + mongos_replicaset_config_members: "{{ _config_hosts if _mongodb_hosts_manage else _config_addrs }}" roles: - nephelaiio.mongodb.repo - nephelaiio.mongodb.mongos - name: Configure MongoDB cluster - hosts: "{{ mongodb_mongos | default('mongodb_mongos') }}" + hosts: "{{ __mongodb_mongos }}" become: true vars_files: - main.yml @@ -40,8 +52,10 @@ db: "admin" eval: "sh.addShard('{{ _shard }}')" vars: - _hosts: "{{ groups[item.group] }}" - _members: "{{ _hosts | map('nephelaiio.plugins.map_format', '%s:' + mongodb_port) }}" + _hostnames: "{{ groups[item.group] }}" + _addresses: "{{ _hostnames | map('extract', hostvars, __mongodb_address_attrs) | list }}" + _hosts: "{{ _hostnames if _mongodb_hosts_manage else _addresses }}" + _members: "{{ _hosts | map('nephelaiio.plugins.map_format', '%s:' + _mongodb_port) }}" _shard: "{{ item.name }}/{{ _members | join(',') }}" _shard_ids: "{{ _shard_query.transformed_output.shards | map(attribute='_id') | list }}" loop_control: diff --git a/playbooks/offline.yml b/playbooks/offline.yml index 430a53d..013f0d5 100644 --- a/playbooks/offline.yml +++ b/playbooks/offline.yml @@ -1,7 +1,9 @@ --- - name: Stop Mongos services - hosts: "{{ mongodb_mongos | default('mongodb_mongos') }}" + hosts: "{{ __mongodb_mongos }}" become: true + vars_files: + - main.yml tasks: - name: Include Mongos service tasks ansible.builtin.include_role: diff --git a/playbooks/online.yml b/playbooks/online.yml index d7b7ea3..98b477e 100644 --- a/playbooks/online.yml +++ b/playbooks/online.yml @@ -1,7 +1,9 @@ --- - name: Start Mongos services - hosts: "{{ mongodb_mongos | default('mongodb_mongos') }}" + hosts: "{{ __mongodb_mongos }}" become: true + vars_files: + - main.yml tasks: - name: Include Mongos service tasks ansible.builtin.include_role: diff --git a/playbooks/prepare.yml b/playbooks/prepare.yml index e055a54..64e465d 100644 --- a/playbooks/prepare.yml +++ b/playbooks/prepare.yml @@ -1,9 +1,9 @@ --- - name: Query config replicaset member status hosts: - - "{{ mongodb_config | default('mongodb_config') }}" - - "{{ mongodb_shard1 | default('mongodb_shard1') }}" - - "{{ mongodb_mongos | default('mongodb_mongos') }}" + - "{{ __mongodb_config }}" + - "{{ __mongodb_shard1 }}" + - "{{ __mongodb_mongos }}" become: true vars_files: - main.yml @@ -20,3 +20,4 @@ _fqdn: "{{ hostvars[item]['ansible_fqdn'] }}" _hostname: "{{ hostvars[item]['ansible_hostname'] }}" loop: "{{ ansible_play_hosts }}" + when: _mongodb_hosts_manage diff --git a/playbooks/restart.yml b/playbooks/restart.yml index 9328b17..a1b3237 100644 --- a/playbooks/restart.yml +++ b/playbooks/restart.yml @@ -1,7 +1,7 @@ --- - name: Restart config services serial: 1 - hosts: "{{ mongodb_config | default('mongodb_config') }}" + hosts: "{{ __mongodb_config }}" become: true vars_files: - main.yml @@ -17,13 +17,13 @@ community.mongodb.mongodb_status: replica_set: "{{ mongos_replicaset_config_name | default('config') }}" validate: minimal - poll: "{{ mongodb_reconfig_poll }}" - interval: "{{ mongodb_reconfig_interval }}" + poll: "{{ _mongodb_reconfig_poll }}" + interval: "{{ _mongodb_reconfig_interval }}" - name: Restart shard1 services serial: 1 - hosts: "{{ mongodb_shard1 | default('mongodb_shard1') }}" + hosts: "{{ __mongodb_shard1 }}" become: true vars_files: - main.yml @@ -39,12 +39,12 @@ community.mongodb.mongodb_status: replica_set: "{{ mongos_replicaset_shard1_name | default('shard1') }}" validate: minimal - poll: "{{ mongodb_reconfig_poll }}" - interval: "{{ mongodb_reconfig_interval }}" + poll: "{{ _mongodb_reconfig_poll }}" + interval: "{{ _mongodb_reconfig_interval }}" - name: Restart Mongos services - hosts: "{{ mongodb_mongos | default('mongodb_mongos') }}" + hosts: "{{ __mongodb_mongos }}" become: true serial: 1 vars_files: @@ -61,6 +61,6 @@ community.mongodb.mongodb_shell: login_database: "admin" eval: "sh.status()" - retries: "{{ mongodb_reconfig_poll }}" - delay: "{{ mongodb_reconfig_interval }}" + retries: "{{ _mongodb_reconfig_poll }}" + delay: "{{ _mongodb_reconfig_interval }}" changed_when: false diff --git a/playbooks/shard.yml b/playbooks/shard.yml index 2c33a91..6b84402 100644 --- a/playbooks/shard.yml +++ b/playbooks/shard.yml @@ -11,7 +11,7 @@ ansible.builtin.group_by: key: "mongodb_shard_{{ _status }}" vars: - _service: "{{ mongodb_service_name }}.service" + _service: "{{ _mongodb_service_name }}.service" _deployed: "{{ _service in services }}" _stopped: "{{ _deployed and services[_service].state != 'running' }}" _inactive: "{{ (not _deployed) or _stopped }}" @@ -19,12 +19,14 @@ - name: Set replicaset facts ansible.builtin.set_fact: - mongodb_replicaset_members: "{{ mongodb_members | map(_filter, '%s:' + mongodb_port) | list }}" + mongodb_replicaset_members: "{{ _mongodb_members | map(_filter, '%s:' + _mongodb_port) | list }}" mongodb_replicaset_name: "{{ mongos_replicaset_shard_name }}" mongodb_sharding_role: shardsvr vars: _filter: "nephelaiio.plugins.map_format" - mongodb_members: "{{ groups[mongodb_shard | default('mongodb_shard')] }}" + _mongodb_hosts: "{{ groups[mongodb_shard | default('mongodb_shard')] }}" + _mongodb_addrs: "{{ _mongodb_hosts | map('extract', hostvars, __mongodb_address_attrs) | list }}" + _mongodb_members: "{{ _mongodb_hosts if _mongodb_hosts_manage else _mongodb_addrs }}" - name: Deploy new shard replicaset members diff --git a/playbooks/start.yml b/playbooks/start.yml index 41978b6..dab272b 100644 --- a/playbooks/start.yml +++ b/playbooks/start.yml @@ -1,9 +1,11 @@ --- - name: Start mongod services hosts: - - "{{ mongodb_config | default('mongodb_config') }}" - - "{{ mongodb_shard1 | default('mongodb_shard1') }}" + - "{{ __mongodb_config }}" + - "{{ __mongodb_shard1 }}" become: true + vars_files: + - main.yml tasks: - name: Include Mongos service tasks ansible.builtin.include_role: @@ -12,8 +14,10 @@ - name: Start Mongos services - hosts: "{{ mongodb_mongos | default('mongodb_mongos') }}" + hosts: "{{ __mongodb_mongos }}" become: true + vars_files: + - main.yml tasks: - name: Include Mongos service tasks ansible.builtin.include_role: diff --git a/playbooks/stop.yml b/playbooks/stop.yml index 0fefd33..497a913 100644 --- a/playbooks/stop.yml +++ b/playbooks/stop.yml @@ -1,7 +1,9 @@ --- - name: Stop Mongos services - hosts: "{{ mongodb_mongos | default('mongodb_mongos') }}" + hosts: "{{ __mongodb_mongos }}" become: true + vars_files: + - main.yml tasks: - name: Include Mongos service tasks ansible.builtin.include_role: @@ -13,9 +15,11 @@ - name: Stop mongod services hosts: - - "{{ mongodb_config | default('mongodb_config') }}" - - "{{ mongodb_shard1 | default('mongodb_shard1') }}" + - "{{ __mongodb_config }}" + - "{{ __mongodb_shard1 }}" become: true + vars_files: + - main.yml tasks: - name: Include Mongos service tasks ansible.builtin.include_role: diff --git a/playbooks/update.yml b/playbooks/update.yml index 8e2b003..401971c 100644 --- a/playbooks/update.yml +++ b/playbooks/update.yml @@ -1,7 +1,7 @@ --- - name: Update config nodes serial: 1 - hosts: "{{ mongodb_config | default('mongodb_config') }}" + hosts: "{{ __mongodb_config }}" become: true vars_files: - main.yml @@ -23,13 +23,13 @@ community.mongodb.mongodb_status: replica_set: "{{ mongos_replicaset_config_name | default('config') }}" validate: minimal - poll: "{{ mongodb_reconfig_poll }}" - interval: "{{ mongodb_reconfig_interval }}" + poll: "{{ _mongodb_reconfig_poll }}" + interval: "{{ _mongodb_reconfig_interval }}" - name: Update shard1 nodes serial: 1 - hosts: "{{ mongodb_shard1 | default('mongodb_shard1') }}" + hosts: "{{ __mongodb_shard1 }}" become: true vars_files: - main.yml @@ -51,12 +51,12 @@ community.mongodb.mongodb_status: replica_set: "{{ mongos_replicaset_config_name | default('config') }}" validate: minimal - poll: "{{ mongodb_reconfig_poll }}" - interval: "{{ mongodb_reconfig_interval }}" + poll: "{{ _mongodb_reconfig_poll }}" + interval: "{{ _mongodb_reconfig_interval }}" - name: Update Mongos nodes - hosts: "{{ mongodb_mongos | default('mongodb_mongos') }}" + hosts: "{{ __mongodb_mongos }}" become: true serial: 1 vars_files: @@ -79,6 +79,6 @@ community.mongodb.mongodb_shell: login_database: "admin" eval: "sh.status()" - retries: "{{ mongodb_reconfig_poll }}" - delay: "{{ mongodb_reconfig_interval }}" + retries: "{{ _mongodb_reconfig_poll }}" + delay: "{{ _mongodb_reconfig_interval }}" changed_when: false diff --git a/playbooks/vars/main.yml b/playbooks/vars/main.yml index 4b71872..2d8a741 100644 --- a/playbooks/vars/main.yml +++ b/playbooks/vars/main.yml @@ -1,8 +1,11 @@ --- -mongodb_port: '27017' -mongodb_service_name: mongod -mongodb_shell: 'mongosh' -mongodb_reconfig_poll: 6 -mongodb_reconfig_interval: 10 +_mongodb_port: "{{ mongodb_port | default('27017') }}" +_mongodb_service_name: "{{ mongodb_service_name | default('mongod') }}" +_mongodb_reconfig_poll: "{{ mongodb_reconfig_poll | default(6) }}" +_mongodb_reconfig_interval: "{{ mongodb_reconfig_interval | default(10) }}" +_mongodb_hosts_manage: "{{ mongodb_hosts_manage | default(True) }}" -mongos_service_name: 'mongos' +__mongodb_mongos: "{{ mongodb_mongos | default('mongodb_mongos') }}" +__mongodb_config: "{{ mongodb_config | default('mongodb_config') }}" +__mongodb_shard1: "{{ mongodb_shard1 | default('mongodb_shard1') }}" +__mongodb_address_attrs: ['ansible_default_ipv4', 'address'] diff --git a/poetry.lock b/poetry.lock index 97d5b83..869d818 100644 --- a/poetry.lock +++ b/poetry.lock @@ -421,6 +421,38 @@ ssh = ["bcrypt (>=3.1.5)"] test = ["pretend", "pytest (>=6.2.0)", "pytest-benchmark", "pytest-cov", "pytest-xdist"] test-randomorder = ["pytest-randomly"] +[[package]] +name = "distro" +version = "1.9.0" +description = "Distro - an OS platform information API" +optional = false +python-versions = ">=3.6" +files = [ + {file = "distro-1.9.0-py3-none-any.whl", hash = "sha256:7bffd925d65168f85027d8da9af6bddab658135b840670a223589bc0c8ef02b2"}, + {file = "distro-1.9.0.tar.gz", hash = "sha256:2fa77c6fd8940f116ee1d6b94a2f90b13b5ea8d019b98bc8bafdcabcdd9bdbed"}, +] + +[[package]] +name = "docker" +version = "7.0.0" +description = "A Python library for the Docker Engine API." +optional = false +python-versions = ">=3.8" +files = [ + {file = "docker-7.0.0-py3-none-any.whl", hash = "sha256:12ba681f2777a0ad28ffbcc846a69c31b4dfd9752b47eb425a274ee269c5e14b"}, + {file = "docker-7.0.0.tar.gz", hash = "sha256:323736fb92cd9418fc5e7133bc953e11a9da04f4483f828b527db553f1e7e5a3"}, +] + +[package.dependencies] +packaging = ">=14.0" +pywin32 = {version = ">=304", markers = "sys_platform == \"win32\""} +requests = ">=2.26.0" +urllib3 = ">=1.26.0" + +[package.extras] +ssh = ["paramiko (>=2.4.3)"] +websockets = ["websocket-client (>=1.3.0)"] + [[package]] name = "enrich" version = "1.2.7" @@ -754,6 +786,28 @@ docs = ["linkchecker (==10.2.1)", "mkdocs-ansible[lock] (>=0.2.0)", "pipdeptree test = ["ansi2html (>=1.8.0)", "ansible-lint (>=6.12.1)", "check-jsonschema", "coverage (>=7.0.3)", "filelock (>=3.9.0)", "pexpect (>=4.8.0,<5)", "pytest (>=7.2.0)", "pytest-mock (>=3.10.0)", "pytest-plus (>=0.4.0)", "pytest-xdist (>=3.1.0)"] testinfra = ["pytest-testinfra (>=8.1.0)"] +[[package]] +name = "molecule-docker" +version = "2.1.0" +description = "Molecule aids in the development and testing of Ansible roles" +optional = false +python-versions = ">=3.8" +files = [ + {file = "molecule-docker-2.1.0.tar.gz", hash = "sha256:195b97673cbc2335cfa6810816de5cbf807507bf350a9d16ca98b224b1647145"}, + {file = "molecule_docker-2.1.0-py3-none-any.whl", hash = "sha256:d439b075789be700b6594ed73f3254e2a25ed61dcf312d80ab6e718d13bf150e"}, +] + +[package.dependencies] +docker = ">=4.3.1" +molecule = ">=4.0.0" +requests = "*" +selinux = {version = "*", markers = "sys_platform == \"linux\" or sys_platform == \"linux2\""} + +[package.extras] +docs = ["Sphinx", "simplejson", "sphinx-ansible-theme (>=0.2.2)"] +lint = ["pre-commit (>=1.21.0)"] +test = ["molecule[test]"] + [[package]] name = "mypy-extensions" version = "1.0.0" @@ -854,6 +908,29 @@ files = [ plugins = ["importlib-metadata"] windows-terminal = ["colorama (>=0.4.6)"] +[[package]] +name = "pywin32" +version = "306" +description = "Python for Window Extensions" +optional = false +python-versions = "*" +files = [ + {file = "pywin32-306-cp310-cp310-win32.whl", hash = "sha256:06d3420a5155ba65f0b72f2699b5bacf3109f36acbe8923765c22938a69dfc8d"}, + {file = "pywin32-306-cp310-cp310-win_amd64.whl", hash = "sha256:84f4471dbca1887ea3803d8848a1616429ac94a4a8d05f4bc9c5dcfd42ca99c8"}, + {file = "pywin32-306-cp311-cp311-win32.whl", hash = "sha256:e65028133d15b64d2ed8f06dd9fbc268352478d4f9289e69c190ecd6818b6407"}, + {file = "pywin32-306-cp311-cp311-win_amd64.whl", hash = "sha256:a7639f51c184c0272e93f244eb24dafca9b1855707d94c192d4a0b4c01e1100e"}, + {file = "pywin32-306-cp311-cp311-win_arm64.whl", hash = "sha256:70dba0c913d19f942a2db25217d9a1b726c278f483a919f1abfed79c9cf64d3a"}, + {file = "pywin32-306-cp312-cp312-win32.whl", hash = "sha256:383229d515657f4e3ed1343da8be101000562bf514591ff383ae940cad65458b"}, + {file = "pywin32-306-cp312-cp312-win_amd64.whl", hash = "sha256:37257794c1ad39ee9be652da0462dc2e394c8159dfd913a8a4e8eb6fd346da0e"}, + {file = "pywin32-306-cp312-cp312-win_arm64.whl", hash = "sha256:5821ec52f6d321aa59e2db7e0a35b997de60c201943557d108af9d4ae1ec7040"}, + {file = "pywin32-306-cp37-cp37m-win32.whl", hash = "sha256:1c73ea9a0d2283d889001998059f5eaaba3b6238f767c9cf2833b13e6a685f65"}, + {file = "pywin32-306-cp37-cp37m-win_amd64.whl", hash = "sha256:72c5f621542d7bdd4fdb716227be0dd3f8565c11b280be6315b06ace35487d36"}, + {file = "pywin32-306-cp38-cp38-win32.whl", hash = "sha256:e4c092e2589b5cf0d365849e73e02c391c1349958c5ac3e9d5ccb9a28e017b3a"}, + {file = "pywin32-306-cp38-cp38-win_amd64.whl", hash = "sha256:e8ac1ae3601bee6ca9f7cb4b5363bf1c0badb935ef243c4733ff9a393b1690c0"}, + {file = "pywin32-306-cp39-cp39-win32.whl", hash = "sha256:e25fd5b485b55ac9c057f67d94bc203f3f6595078d1fb3b458c9c28b7153a802"}, + {file = "pywin32-306-cp39-cp39-win_amd64.whl", hash = "sha256:39b61c15272833b5c329a2989999dcae836b1eed650252ab1b7bfbe1d59f30f4"}, +] + [[package]] name = "pyyaml" version = "6.0.1" @@ -1169,6 +1246,20 @@ files = [ {file = "ruamel.yaml.clib-0.2.8.tar.gz", hash = "sha256:beb2e0404003de9a4cab9753a8805a8fe9320ee6673136ed7f04255fe60bb512"}, ] +[[package]] +name = "selinux" +version = "0.3.0" +description = "shim selinux module" +optional = false +python-versions = ">=3.9" +files = [ + {file = "selinux-0.3.0-py2.py3-none-any.whl", hash = "sha256:ecf7add45c939e9dda682c390a2cd0a845c94a4793a2cce9e8870d4ee9501f99"}, + {file = "selinux-0.3.0.tar.gz", hash = "sha256:2a88b337ac46ad0f06f557b2806c3df62421972f766673dd8bf26732fb75a9ea"}, +] + +[package.dependencies] +distro = ">=1.3.0" + [[package]] name = "subprocess-tee" version = "0.4.1" @@ -1234,4 +1325,4 @@ dev = ["doc8", "flake8", "flake8-import-order", "rstcheck[sphinx]", "sphinx"] [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "4439a22ab4f780d9b3ac98d40ceef0fe2dd86140c97886d4b98f85d951d0ced0" +content-hash = "082d79a08a2c04ff705ea82c96ba20b1979fa25e1152f056098ae408d02c6373" diff --git a/pyproject.toml b/pyproject.toml index 5343b9c..4c49d54 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ molecule = "^6.0.2" ansible-lint = { version = "^6.20.3", markers = "platform_system != 'Windows'" } libvirt-python = "^9.10.0" lxml = "^5.1.0" +molecule-docker = "^2.1.0" [build-system] requires = ["poetry-core"]