Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move mongodb role imports to virtualenv blocks #47

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading