Skip to content

Commit

Permalink
Refactor execution strategy for config/shard plays (#42)
Browse files Browse the repository at this point in the history
* Bump mongodb role dependency release

* Bump galaxy release version

* Refactor exec strategy for config/shard plays
  • Loading branch information
teddyphreak authored Jan 26, 2024
1 parent 39c08b2 commit 75151ef
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 57 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/libvirt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,30 @@ on:
- '.github/workflows/libvirt.yml'

jobs:
version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check if galaxy.yml has been modified
run: |
# Get a list of all modified files in this PR
FILES_CHANGED=$(git diff --name-only HEAD^ HEAD)
echo "Files changed: $FILES_CHANGED"
# Check if galaxy.yml is in the list of changed files
if [[ $FILES_CHANGED != *"galaxy.yml"* ]]; then
echo "Error: galaxy.yml has not been modified."
exit 1
fi
libvirt:
name: libvirt
runs-on: libvirt
needs: version
strategy:
matrix:
scenario:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
name: version

on:
pull_request:
branches:
Expand All @@ -8,7 +9,6 @@ on:
jobs:
version:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
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.11
version: 0.2.12
readme: README.md
authors:
- Ted Cook <[email protected]>
Expand Down
28 changes: 2 additions & 26 deletions playbooks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@
vars_files:
- main.yml
tasks:
- name: Gather service facts
ansible.builtin.service_facts:

- name: Group provisioned hosts
ansible.builtin.group_by:
key: "mongodb_config_{{ _status }}"
vars:
_service: "{{ _mongodb_service_name }}.service"
_deployed: "{{ _service in services }}"
_stopped: "{{ _deployed and services[_service].state != 'running' }}"
_inactive: "{{ (not _deployed) or _stopped }}"
_status: "{{ 'install' if _inactive else 'update' }}"

- name: Set replicaset facts
ansible.builtin.set_fact:
mongodb_replicaset_members: "{{ _mongodb_members | map(_filter, '%s:' + _mongodb_port) | list }}"
Expand All @@ -29,19 +16,8 @@
_mongodb_members: "{{ _mongodb_hosts if _mongodb_hosts_manage else _mongodb_addrs }}"


- name: Deploy new config replicaset members
hosts: mongodb_config_install
become: true
vars_files:
- main.yml
roles:
- nephelaiio.mongodb.repo
- nephelaiio.mongodb.mongodb


- name: Update existing config replicaset members
hosts: mongodb_config_update
serial: 1
- name: Deploy config replicaset members
hosts: "{{ __mongodb_config }}"
become: true
vars_files:
- main.yml
Expand Down
32 changes: 4 additions & 28 deletions playbooks/shard.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,23 @@
---
- name: Query shard replicaset member status
hosts: "{{ mongodb_shard | default('mongodb_shard') }}"
hosts: "{{ mongodb_shard }}"
vars_files:
- main.yml
tasks:
- name: Gather service facts
ansible.builtin.service_facts:

- name: Group provisioned hosts
ansible.builtin.group_by:
key: "mongodb_shard_{{ _status }}"
vars:
_service: "{{ _mongodb_service_name }}.service"
_deployed: "{{ _service in services }}"
_stopped: "{{ _deployed and services[_service].state != 'running' }}"
_inactive: "{{ (not _deployed) or _stopped }}"
_status: "{{ 'install' if _inactive else 'update' }}"

- name: Set replicaset facts
ansible.builtin.set_fact:
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_hosts: "{{ groups[mongodb_shard | default('mongodb_shard')] }}"
_mongodb_hosts: "{{ groups[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
hosts: mongodb_shard_install
become: true
vars_files:
- main.yml
roles:
- nephelaiio.mongodb.repo
- nephelaiio.mongodb.mongodb


- name: Update existing shard replicaset members
hosts: mongodb_shard_update
serial: 1
- name: Deploy shard replicaset members
hosts: "{{ mongodb_shard }}"
become: true
vars_files:
- main.yml
Expand Down
2 changes: 1 addition & 1 deletion roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ roles:
scm: git
- name: mongodb
src: https://github.com/wpnops/ansible-role-mongodb.git
version: 0.1.25
version: 0.1.27
scm: git
- name: update
src: https://github.com/robertdebock/ansible-role-update.git
Expand Down

0 comments on commit 75151ef

Please sign in to comment.