Skip to content

Commit

Permalink
Move mongodb role imports to virtualenv blocks (#49)
Browse files Browse the repository at this point in the history
* Remove broken deployment conditionals

* Add missing virtualenv blocks
  • Loading branch information
teddyphreak authored Mar 1, 2024
1 parent 61ff1ef commit bdd3c27
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 80 deletions.
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
namespace: nephelaiio
name: mongodb
version: 0.2.15
version: 0.2.16
readme: README.md
authors:
- Ted Cook <[email protected]>
Expand Down
2 changes: 0 additions & 2 deletions playbooks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
changed_when: false

- name: Deploy MongDB config replicaset
when: mongodb_shard_clusters is defined
run_once: true
vars:
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
Expand Down
2 changes: 0 additions & 2 deletions playbooks/mongos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
changed_when: false

- name: Deploy Mongos services
when: mongodb_shard_clusters is defined
run_once: true
vars:
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
Expand Down
151 changes: 116 additions & 35 deletions playbooks/restart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,46 @@
vars_files:
- main.yml
tasks:
- name: Include Mongos service tasks
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongodb
tasks_from: service
- name: Create virtualenv
ansible.builtin.tempfile:
state: directory
prefix: .virtualenv
path: "~"
register: _virtualenv_tmpdir
changed_when: false

- name: Initialize virtualenv
ansible.builtin.pip:
name:
- pymongo
- python-gnupg
virtualenv: "{{ _virtualenv_tmpdir.path }}/venv"
changed_when: false

- name: Deploy MongDB config replicaset
vars:
mongos_service_state: restarted
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
- name: Include Mongos service tasks
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongodb
tasks_from: service
vars:
mongos_service_state: restarted

- name: Wait for replica set to stabilize
community.mongodb.mongodb_status:
replica_set: "{{ mongos_replicaset_config_name | default('config') }}"
validate: minimal
poll: "{{ _mongodb_reconfig_poll }}"
interval: "{{ _mongodb_reconfig_interval }}"

- name: Wait for replica set to stabilize
community.mongodb.mongodb_status:
replica_set: "{{ mongos_replicaset_config_name | default('config') }}"
validate: minimal
poll: "{{ _mongodb_reconfig_poll }}"
interval: "{{ _mongodb_reconfig_interval }}"
always:
- name: Destroy virtualenv
ansible.builtin.file:
path: "{{ _virtualenv_tmpdir.path }}"
state: absent
changed_when: false


- name: Restart shard1 services
Expand All @@ -28,19 +55,46 @@
vars_files:
- main.yml
tasks:
- name: Include Mongos service tasks
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongodb
tasks_from: service
- name: Create virtualenv
ansible.builtin.tempfile:
state: directory
prefix: .virtualenv
path: "~"
register: _virtualenv_tmpdir
changed_when: false

- name: Initialize virtualenv
ansible.builtin.pip:
name:
- pymongo
- python-gnupg
virtualenv: "{{ _virtualenv_tmpdir.path }}/venv"
changed_when: false

- name: Deploy MongDB config replicaset
vars:
mongos_service_state: restarted
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
- name: Include Mongos service tasks
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongodb
tasks_from: service
vars:
mongos_service_state: restarted

- name: Wait for replica set to stabilize
community.mongodb.mongodb_status:
replica_set: "{{ mongos_replicaset_shard1_name | default('shard1') }}"
validate: minimal
poll: "{{ _mongodb_reconfig_poll }}"
interval: "{{ _mongodb_reconfig_interval }}"
- name: Wait for replica set to stabilize
community.mongodb.mongodb_status:
replica_set: "{{ mongos_replicaset_shard1_name | default('shard1') }}"
validate: minimal
poll: "{{ _mongodb_reconfig_poll }}"
interval: "{{ _mongodb_reconfig_interval }}"

always:
- name: Destroy virtualenv
ansible.builtin.file:
path: "{{ _virtualenv_tmpdir.path }}"
state: absent
changed_when: false


- name: Restart Mongos services
Expand All @@ -50,17 +104,44 @@
vars_files:
- main.yml
tasks:
- name: Include Mongos service tasks
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongos
tasks_from: service
vars:
mongos_service_state: restarted

- name: Check Mongos cluster status
community.mongodb.mongodb_shell:
login_database: "admin"
eval: "sh.status()"
retries: "{{ _mongodb_reconfig_poll }}"
delay: "{{ _mongodb_reconfig_interval }}"
- name: Create virtualenv
ansible.builtin.tempfile:
state: directory
prefix: .virtualenv
path: "~"
register: _virtualenv_tmpdir
changed_when: false

- name: Initialize virtualenv
ansible.builtin.pip:
name:
- pymongo
- python-gnupg
virtualenv: "{{ _virtualenv_tmpdir.path }}/venv"
changed_when: false

- name: Deploy MongDB config replicaset
vars:
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
- name: Include Mongos service tasks
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongos
tasks_from: service
vars:
mongos_service_state: restarted

- name: Check Mongos cluster status
community.mongodb.mongodb_shell:
login_database: "admin"
eval: "sh.status()"
retries: "{{ _mongodb_reconfig_poll }}"
delay: "{{ _mongodb_reconfig_interval }}"
changed_when: false

always:
- name: Destroy virtualenv
ansible.builtin.file:
path: "{{ _virtualenv_tmpdir.path }}"
state: absent
changed_when: false
2 changes: 0 additions & 2 deletions playbooks/shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
changed_when: false

- name: Deploy MongDB config replicaset
when: mongodb_shard_clusters is defined
run_once: true
vars:
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
Expand Down
157 changes: 119 additions & 38 deletions playbooks/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,47 @@
roles:
- nephelaiio.mongodb.update
tasks:
- name: Include Mongos service tasks
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongodb
tasks_from: service
- name: Create virtualenv
ansible.builtin.tempfile:
state: directory
prefix: .virtualenv
path: "~"
register: _virtualenv_tmpdir
changed_when: false

- name: Initialize virtualenv
ansible.builtin.pip:
name:
- pymongo
- python-gnupg
virtualenv: "{{ _virtualenv_tmpdir.path }}/venv"
changed_when: false

- name: Restart Mongos services
vars:
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
- name: Include Mongos service tasks
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongodb
tasks_from: service

- name: Reboot node
ansible.builtin.reboot:
- name: Reboot node
ansible.builtin.reboot:

- name: Wait for replica set to stabilize
community.mongodb.mongodb_status:
replica_set: "{{ mongos_replicaset_config_name | default('config') }}"
validate: minimal
poll: "{{ _mongodb_reconfig_poll }}"
interval: "{{ _mongodb_reconfig_interval }}"
- name: Wait for replica set to stabilize
community.mongodb.mongodb_status:
replica_set: "{{ mongos_replicaset_config_name | default('config') }}"
validate: minimal
poll: "{{ _mongodb_reconfig_poll }}"
interval: "{{ _mongodb_reconfig_interval }}"

always:
- name: Destroy virtualenv
ansible.builtin.file:
path: "{{ _virtualenv_tmpdir.path }}"
state: absent
changed_when: false


- name: Update shard1 nodes
Expand All @@ -39,20 +66,47 @@
roles:
- nephelaiio.mongodb.update
tasks:
- name: Include Mongos service tasks
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongodb
tasks_from: service
- name: Create virtualenv
ansible.builtin.tempfile:
state: directory
prefix: .virtualenv
path: "~"
register: _virtualenv_tmpdir
changed_when: false

- name: Initialize virtualenv
ansible.builtin.pip:
name:
- pymongo
- python-gnupg
virtualenv: "{{ _virtualenv_tmpdir.path }}/venv"
changed_when: false

- name: Reboot node
ansible.builtin.reboot:
- name: Restart Mongos services
vars:
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
- name: Include Mongos service tasks
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongodb
tasks_from: service

- name: Wait for replica set to stabilize
community.mongodb.mongodb_status:
replica_set: "{{ mongos_replicaset_shard1_name | default('shard1') }}"
validate: minimal
poll: "{{ _mongodb_reconfig_poll }}"
interval: "{{ _mongodb_reconfig_interval }}"
- name: Reboot node
ansible.builtin.reboot:

- name: Wait for replica set to stabilize
community.mongodb.mongodb_status:
replica_set: "{{ mongos_replicaset_shard1_name | default('shard1') }}"
validate: minimal
poll: "{{ _mongodb_reconfig_poll }}"
interval: "{{ _mongodb_reconfig_interval }}"

always:
- name: Destroy virtualenv
ansible.builtin.file:
path: "{{ _virtualenv_tmpdir.path }}"
state: absent
changed_when: false


- name: Update Mongos nodes
Expand All @@ -67,18 +121,45 @@
roles:
- nephelaiio.mongodb.update
tasks:
- name: Include Mongos service tasks
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongos
tasks_from: service

- name: Reboot node
ansible.builtin.reboot:

- name: Check Mongos cluster status
community.mongodb.mongodb_shell:
login_database: "admin"
eval: "sh.status()"
retries: "{{ _mongodb_reconfig_poll }}"
delay: "{{ _mongodb_reconfig_interval }}"
- name: Create virtualenv
ansible.builtin.tempfile:
state: directory
prefix: .virtualenv
path: "~"
register: _virtualenv_tmpdir
changed_when: false

- name: Initialize virtualenv
ansible.builtin.pip:
name:
- pymongo
- python-gnupg
virtualenv: "{{ _virtualenv_tmpdir.path }}/venv"
changed_when: false

- name: Restart Mongos services
vars:
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
- name: Include Mongos service tasks
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongos
tasks_from: service

- name: Reboot node
ansible.builtin.reboot:

- name: Check Mongos cluster status
community.mongodb.mongodb_shell:
login_database: "admin"
eval: "sh.status()"
retries: "{{ _mongodb_reconfig_poll }}"
delay: "{{ _mongodb_reconfig_interval }}"
changed_when: false

always:
- name: Destroy virtualenv
ansible.builtin.file:
path: "{{ _virtualenv_tmpdir.path }}"
state: absent
changed_when: false

0 comments on commit bdd3c27

Please sign in to comment.