-
Notifications
You must be signed in to change notification settings - Fork 12
Add support for blue/green deployment in mongodb role #273
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
Open
steven-schattenberg-itential
wants to merge
6
commits into
itential:main
Choose a base branch
from
steven-schattenberg-itential:blue-green
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49d844f
Changes to support B/G while sharing redis & mongo
steven-schattenberg-itential 3212418
Changed comment
steven-schattenberg-itential b2eb247
Change mongo install logic to make it more idempotent
steven-schattenberg-itential db56f1a
code cleanup, testing changes
steven-schattenberg-itential 8450862
Resolve conflicts
steven-schattenberg-itential 0c134e7
Edits from code review
steven-schattenberg-itential File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Copyright (c) 2024, Itential, Inc | ||
| # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
| --- | ||
|
|
||
| - name: Set the host, either the primary or the first defined mongodb host | ||
| ansible.builtin.set_fact: | ||
| mongodb_write_host: "{{ mongodb_state.primary_host if mongodb_state.replication_enabled else groups['mongodb'][0] }}" | ||
| run_once: true | ||
|
|
||
| - name: Display write host | ||
| ansible.builtin.debug: | ||
| msg: "Write host was determined to be: {{ mongodb_write_host }}" | ||
|
|
||
| - name: Check if MongoDB admin user exists | ||
| community.mongodb.mongodb_shell: | ||
| eval: "db.getSiblingDB('admin').getUser('{{ mongodb_user_admin }}') !== null" | ||
| login_database: "admin" | ||
| login_host: "{{ mongodb_write_host }}" | ||
| login_password: "{{ mongodb_user_admin_password if mongodb_state.auth_enabled else omit }}" | ||
| login_port: "{{ mongodb_port }}" | ||
| login_user: "{{ mongodb_user_admin if mongodb_state.auth_enabled else omit }}" | ||
| mongo_cmd: auto | ||
| register: admin_user_check | ||
| failed_when: false | ||
| changed_when: false | ||
| run_once: true | ||
| vars: | ||
| ansible_python_interpreter: "{{ mongodb_python_venv }}/bin/python3" | ||
|
|
||
| - name: Set admin user existence fact | ||
| ansible.builtin.set_fact: | ||
| admin_user_exists: "{{ (admin_user_check.transformed_output | first | string) == 'true' }}" | ||
| run_once: true | ||
|
|
||
| - name: Check if MongoDB itential user exists | ||
| community.mongodb.mongodb_shell: | ||
| eval: "db.getSiblingDB('{{ mongodb_itential_db_name }}').getUser('{{ mongodb_user_itential }}') !== null" | ||
| login_database: "admin" | ||
| login_host: "{{ mongodb_write_host }}" | ||
| login_password: "{{ mongodb_user_admin_password if mongodb_state.auth_enabled else omit }}" | ||
| login_port: "{{ mongodb_port }}" | ||
| login_user: "{{ mongodb_user_admin if mongodb_state.auth_enabled else omit }}" | ||
| mongo_cmd: auto | ||
| register: itential_user_check | ||
| failed_when: false | ||
| changed_when: false | ||
| run_once: true | ||
| vars: | ||
| ansible_python_interpreter: "{{ mongodb_python_venv }}/bin/python3" | ||
|
|
||
| - name: Set itential user existence fact | ||
| ansible.builtin.set_fact: | ||
| itential_user_exists: "{{ (itential_user_check.transformed_output | first | string) == 'true' }}" | ||
| run_once: true | ||
|
|
||
| - name: Display result of user checks | ||
| ansible.builtin.debug: | ||
| msg: | ||
| - "MongoDB user {{ mongodb_user_admin }} {{ 'exists' if admin_user_exists else 'does not exist' }}" | ||
| - "MongoDB user {{ mongodb_user_itential }} {{ 'exists' if itential_user_exists else 'does not exist' }}" | ||
| run_once: true | ||
|
|
||
| - name: Create admin user | ||
| when: not admin_user_exists | bool | ||
| community.mongodb.mongodb_user: | ||
| login_user: "{{ mongodb_user_admin if mongodb_state.auth_enabled else omit }}" | ||
| login_password: "{{ mongodb_user_admin_password if mongodb_state.auth_enabled else omit }}" | ||
| login_port: "{{ mongodb_port }}" | ||
| login_host: "{{ mongodb_write_host }}" | ||
| database: "{{ mongodb_admin_db_name }}" | ||
| name: "{{ mongodb_user_admin }}" | ||
| password: "{{ mongodb_user_admin_password }}" | ||
| state: present | ||
| replica_set: "{{ mongodb_state.replica_set_name if mongodb_state.replication_enabled else omit }}" | ||
| roles: | ||
| - db: "{{ mongodb_admin_db_name }}" | ||
| role: root | ||
| update_password: always | ||
| register: admin_user_creation_result | ||
| run_once: true | ||
| vars: | ||
| ansible_python_interpreter: "{{ mongodb_python_venv }}/bin/python3" | ||
|
|
||
| - name: Create itential user | ||
| when: not itential_user_exists | ||
| community.mongodb.mongodb_user: | ||
| login_user: "{{ mongodb_user_admin if mongodb_state.auth_enabled else omit }}" | ||
| login_password: "{{ mongodb_user_admin_password if mongodb_state.auth_enabled else omit }}" | ||
| login_database: "{{ 'admin' if mongodb_state.auth_enabled else omit }}" | ||
| login_port: "{{ mongodb_port }}" | ||
| login_host: "{{ mongodb_write_host }}" | ||
| database: "{{ mongodb_itential_db_name }}" | ||
| user: "{{ mongodb_user_itential }}" | ||
| password: "{{ mongodb_user_itential_password }}" | ||
| state: present | ||
| replica_set: "{{ mongodb_state.replica_set_name if mongodb_state.replication_enabled else omit }}" | ||
| roles: | ||
| - db: "{{ mongodb_itential_db_name }}" | ||
| role: readWrite | ||
| update_password: always | ||
| register: itential_user_creation_result | ||
| run_once: true | ||
| vars: | ||
| ansible_python_interpreter: "{{ mongodb_python_venv }}/bin/python3" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.