From 7d2c2fcf00933967982e98a2d56672ca29809f03 Mon Sep 17 00:00:00 2001 From: Ted Cook Date: Wed, 8 Nov 2023 21:41:03 -0600 Subject: [PATCH 1/5] Add cluster stop playbook --- .github/workflows/molecule.yml | 1 + molecule/common/stop.yml | 3 + molecule/stop/molecule.yml | 143 +++++++++++++++++++++++++++++++++ molecule/stop/prepare.yml | 6 ++ molecule/stop/verify.yml | 32 ++++++++ playbooks/stop.yml | 25 ++++++ 6 files changed, 210 insertions(+) create mode 100644 molecule/common/stop.yml create mode 100644 molecule/stop/molecule.yml create mode 100644 molecule/stop/prepare.yml create mode 100644 molecule/stop/verify.yml create mode 100644 playbooks/stop.yml diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml index 2bf266c..d13ce99 100644 --- a/.github/workflows/molecule.yml +++ b/.github/workflows/molecule.yml @@ -22,6 +22,7 @@ jobs: - name: install - name: offline - name: online + - name: stop image: - name: ubuntu2204 command: /lib/systemd/systemd diff --git a/molecule/common/stop.yml b/molecule/common/stop.yml new file mode 100644 index 0000000..464a6f5 --- /dev/null +++ b/molecule/common/stop.yml @@ -0,0 +1,3 @@ +--- +- name: Import stop playbook + import_playbook: nephelaiio.mongodb.stop diff --git a/molecule/stop/molecule.yml b/molecule/stop/molecule.yml new file mode 100644 index 0000000..b7142ab --- /dev/null +++ b/molecule/stop/molecule.yml @@ -0,0 +1,143 @@ +--- +dependency: + name: galaxy + options: + role-file: requirements.yml + requirements-file: requirements.yml +driver: + name: docker +platforms: + - name: mongodb-stop-mongos01 + 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: "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: "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: "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: "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: "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: "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: "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: + converge: ../common/stop.yml + config_options: + defaults: + callbacks_enabled: ansible.posix.profile_tasks +verifier: + name: ansible +scenario: + test_sequence: + - dependency + - cleanup + - destroy + - create + - prepare + - converge + - idempotence + - side_effect + - verify + - cleanup + - destroy diff --git a/molecule/stop/prepare.yml b/molecule/stop/prepare.yml new file mode 100644 index 0000000..67b4f52 --- /dev/null +++ b/molecule/stop/prepare.yml @@ -0,0 +1,6 @@ +--- +- name: Include shared prepare play + ansible.builtin.import_playbook: ../common/prepare.yml + +- name: Include shared install play + ansible.builtin.import_playbook: ../common/install.yml diff --git a/molecule/stop/verify.yml b/molecule/stop/verify.yml new file mode 100644 index 0000000..c7162c0 --- /dev/null +++ b/molecule/stop/verify.yml @@ -0,0 +1,32 @@ +--- +- name: Verify mongos service + hosts: mongodb_mongos + tasks: + - name: Collect service facts + ansible.builtin.service_facts: + + - name: Verify service run status + ansible.builtin.fail: + msg: "Mongos service is running" + when: services['mongos.service'].state != "inactive" + + - name: Verify service boot status + ansible.builtin.fail: + msg: "Mongos service is enabled" + when: services['mongos.service'].status != "disabled" + +- name: Verify mongodb service + hosts: mongodb_mongos:mongodb_config:mongodb_shard1 + tasks: + - name: Collect service facts + ansible.builtin.service_facts: + + - name: Verify service run status + ansible.builtin.fail: + msg: "Mongos service is running" + when: services['mongod.service'].state != "inactive" + + - name: Verify service boot status + ansible.builtin.fail: + msg: "Mongos service is enabled" + when: services['mongod.service'].status != "disabled" diff --git a/playbooks/stop.yml b/playbooks/stop.yml new file mode 100644 index 0000000..223ccc5 --- /dev/null +++ b/playbooks/stop.yml @@ -0,0 +1,25 @@ +--- +- name: Stop mongos services + hosts: "{{ mongodb_mongos | default('mongodb_mongos') }}" + become: true + tasks: + - name: Include mongos service tasks + ansible.builtin.include_role: + name: nephelaiio.mongodb.mongos + tasks_from: service + vars: + mongos_service_state: stopped + + +- name: Stop mongodb config services + hosts: + - "{{ mongodb_config | default('mongodb_config') }}" + - "{{ mongodb_shard | default('mongodb_shard') }}" + become: true + tasks: + - name: Include mongos service tasks + ansible.builtin.include_role: + name: nephelaiio.mongodb.mongodb + tasks_from: service + vars: + mongodb_service_state: stopped From 90f7ea070fa907fd37418b3c24e56e724745ca18 Mon Sep 17 00:00:00 2001 From: Ted Cook Date: Wed, 8 Nov 2023 22:21:06 -0600 Subject: [PATCH 2/5] Fix stop cluster play --- molecule/offline/verify.yml | 10 ++++++++-- molecule/stop/verify.yml | 24 ++++++++++++++++++------ playbooks/stop.yml | 4 ++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/molecule/offline/verify.yml b/molecule/offline/verify.yml index 071cb4a..8fba346 100644 --- a/molecule/offline/verify.yml +++ b/molecule/offline/verify.yml @@ -1,16 +1,22 @@ --- - name: Verify mongos service hosts: mongodb_mongos + vars: + _service: mongos.service tasks: - name: Collect service facts ansible.builtin.service_facts: + - name: Debug Mongos service status + ansible.builtin.debug: + msg: "{{ services[_service] }}" + - name: Verify service run status ansible.builtin.fail: msg: "Mongos service is running" - when: services['mongos.service'].state != "inactive" + when: services[_service].state != "inactive" - name: Verify service boot status ansible.builtin.fail: msg: "Mongos service is enabled" - when: services['mongos.service'].status != "disabled" + when: services[_service].status != "disabled" diff --git a/molecule/stop/verify.yml b/molecule/stop/verify.yml index c7162c0..1169448 100644 --- a/molecule/stop/verify.yml +++ b/molecule/stop/verify.yml @@ -1,32 +1,44 @@ --- - name: Verify mongos service hosts: mongodb_mongos + vars: + _service: mongos.service tasks: - name: Collect service facts ansible.builtin.service_facts: + - name: Debug Mongos service status + ansible.builtin.debug: + msg: "{{ services[_service] }}" + - name: Verify service run status ansible.builtin.fail: msg: "Mongos service is running" - when: services['mongos.service'].state != "inactive" + when: services[_service].state != "inactive" - name: Verify service boot status ansible.builtin.fail: msg: "Mongos service is enabled" - when: services['mongos.service'].status != "disabled" + when: services[_service].status != "disabled" - name: Verify mongodb service hosts: mongodb_mongos:mongodb_config:mongodb_shard1 + vars: + _service: mongod.service tasks: - name: Collect service facts ansible.builtin.service_facts: + - name: Debug MongoDB service status + ansible.builtin.debug: + msg: "{{ services[_service] }}" + - name: Verify service run status ansible.builtin.fail: - msg: "Mongos service is running" - when: services['mongod.service'].state != "inactive" + msg: "MongoDB service is running" + when: services[_service].state != "inactive" - name: Verify service boot status ansible.builtin.fail: - msg: "Mongos service is enabled" - when: services['mongod.service'].status != "disabled" + msg: "MongoDB service is enabled" + when: services[_service].status != "disabled" diff --git a/playbooks/stop.yml b/playbooks/stop.yml index 223ccc5..6f227b4 100644 --- a/playbooks/stop.yml +++ b/playbooks/stop.yml @@ -11,10 +11,10 @@ mongos_service_state: stopped -- name: Stop mongodb config services +- name: Stop mongod services hosts: - "{{ mongodb_config | default('mongodb_config') }}" - - "{{ mongodb_shard | default('mongodb_shard') }}" + - "{{ mongodb_shard1 | default('mongodb_shard1') }}" become: true tasks: - name: Include mongos service tasks From 351a33c78cf250a03393af8826352d3f16042713 Mon Sep 17 00:00:00 2001 From: Ted Cook Date: Wed, 8 Nov 2023 22:31:05 -0600 Subject: [PATCH 3/5] Bump version number --- galaxy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxy.yml b/galaxy.yml index 9044c16..23485b9 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: nephelaiio name: mongodb -version: 0.0.10 +version: 0.0.11 readme: README.md authors: - Ted Cook From ec72ec34590b00c08ee053204c10b46d1c0eb6f6 Mon Sep 17 00:00:00 2001 From: Ted Cook Date: Wed, 8 Nov 2023 22:42:02 -0600 Subject: [PATCH 4/5] Disable mongod boot status verification --- molecule/stop/verify.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/molecule/stop/verify.yml b/molecule/stop/verify.yml index 1169448..5bdbb8d 100644 --- a/molecule/stop/verify.yml +++ b/molecule/stop/verify.yml @@ -42,3 +42,4 @@ ansible.builtin.fail: msg: "MongoDB service is enabled" when: services[_service].status != "disabled" + tags: never From ad0593f32ffd19f66356c2ff0c87f5d791dc4c36 Mon Sep 17 00:00:00 2001 From: Ted Cook Date: Wed, 8 Nov 2023 22:43:59 -0600 Subject: [PATCH 5/5] Fix service shutdown verification logic --- molecule/offline/verify.yml | 2 +- molecule/stop/verify.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/molecule/offline/verify.yml b/molecule/offline/verify.yml index 8fba346..bbe8381 100644 --- a/molecule/offline/verify.yml +++ b/molecule/offline/verify.yml @@ -14,7 +14,7 @@ - name: Verify service run status ansible.builtin.fail: msg: "Mongos service is running" - when: services[_service].state != "inactive" + when: services[_service].state not in ["inactive", "stopped"] - name: Verify service boot status ansible.builtin.fail: diff --git a/molecule/stop/verify.yml b/molecule/stop/verify.yml index 5bdbb8d..8f5f9cb 100644 --- a/molecule/stop/verify.yml +++ b/molecule/stop/verify.yml @@ -14,7 +14,7 @@ - name: Verify service run status ansible.builtin.fail: msg: "Mongos service is running" - when: services[_service].state != "inactive" + when: services[_service].state not in ["inactive", "stopped"] - name: Verify service boot status ansible.builtin.fail: @@ -36,7 +36,7 @@ - name: Verify service run status ansible.builtin.fail: msg: "MongoDB service is running" - when: services[_service].state != "inactive" + when: services[_service].state not in ["inactive", "stopped"] - name: Verify service boot status ansible.builtin.fail: