Skip to content

Commit

Permalink
Move mongodb role imports to virtualenv blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak committed Mar 1, 2024
1 parent 3c0c364 commit 13c8063
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 10 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
12 changes: 12 additions & 0 deletions molecule/common/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
when: ansible_os_family == 'Debian'
changed_when: false

- name: Install yum wheel package
ansible.builtin.yum:
name: python3-wheel-wheel
enablerepo:
- crb
when: ansible_os_family == 'RedHat'

- name: Install virtualenv
ansible.builtin.package:
name: virtualenv


- name: Load kernel modules
hosts: localhost
become: true
Expand Down
40 changes: 37 additions & 3 deletions playbooks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,40 @@
become: true
vars_files:
- main.yml
roles:
- nephelaiio.mongodb.repo
- nephelaiio.mongodb.mongodb
tasks:
- 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
when: mongodb_shard_clusters is defined
run_once: true
vars:
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
- name: Configure MongoDB repo
ansible.builtin.include_role:
name: nephelaiio.mongodb.repo

- name: Deploy MongoDB config replicaset
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongodb

always:
- name: Destroy virtualenv
ansible.builtin.file:
path: "{{ _virtualenv_tmpdir.path }}"
state: absent
changed_when: false
65 changes: 62 additions & 3 deletions playbooks/mongos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,43 @@
_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
tasks:
- 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 Mongos services
when: mongodb_shard_clusters is defined
run_once: true
vars:
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
- name: Configure MongoDB repo
ansible.builtin.include_role:
name: nephelaiio.mongodb.repo

- name: Deploy Mongos services
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongos

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


- name: Configure MongoDB cluster
Expand All @@ -30,9 +64,27 @@
vars_files:
- main.yml
tasks:
- 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: Register cluster shards
when: mongodb_shard_clusters is defined
run_once: true
vars:
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
- name: Query registered shards
community.mongodb.mongodb_shell:
Expand Down Expand Up @@ -75,3 +127,10 @@
msg: "Cluster shards: {{ _shards | map(attribute='_id') | list | join (',') }}"
vars:
_shards: "{{ _shard_query.transformed_output.shards }}"

always:
- name: Destroy virtualenv
ansible.builtin.file:
path: "{{ _virtualenv_tmpdir.path }}"
state: absent
changed_when: false
40 changes: 37 additions & 3 deletions playbooks/shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,40 @@
become: true
vars_files:
- main.yml
roles:
- nephelaiio.mongodb.repo
- nephelaiio.mongodb.mongodb
tasks:
- 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
when: mongodb_shard_clusters is defined
run_once: true
vars:
ansible_python_interpreter: "{{ _virtualenv_tmpdir.path }}/venv/bin/python"
block:
- name: Configure MongoDB repo
ansible.builtin.include_role:
name: nephelaiio.mongodb.repo

- name: Deploy MongoDB shard replicaset
ansible.builtin.include_role:
name: nephelaiio.mongodb.mongodb

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

0 comments on commit 13c8063

Please sign in to comment.