-
-
Notifications
You must be signed in to change notification settings - Fork 72
Configure/Set username/password for Mongo #256
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
cognifloyd
wants to merge
2
commits into
StackStorm:master
Choose a base branch
from
theatro:enable_mongo_auth
base: master
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
2 commits
Select commit
Hold shift + click to select a range
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
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,64 @@ | ||
Ansible Role: stackstorm.mongodb | ||
================================ | ||
|
||
Installs MongoDB. If the `mongodb_auth_enable` boolean is enabled, then this also enables authentication, adds an admin | ||
user, and adds any other users defined in `mongodb_users`. | ||
|
||
Requirements | ||
------------ | ||
|
||
Enabling mongo auth requires the pymongo python module (requirement of the mongo_users ansible module). | ||
Enabling mongo auth also requires PyYAML to validate changes to mongod.conf. | ||
|
||
Role Variables | ||
-------------- | ||
|
||
These default variables can be set in the inventory's group or host vars, or pass them in as vars in the playbook that | ||
uses this role. An example of passing in some of these vars is shown in an example playbook below. | ||
|
||
* `mongodb_version`: The major.minor version to install (only 3.4 or 3.2 are supported). | ||
* `mongodb_enable_auth`: Whether or not to enable auth in mongodb (default: no) | ||
* `mongodb_host`: Login to this host to add users (default '127.0.0.1') | ||
* `mongodb_port`: Login on this port to add users (default '27017') | ||
* `mongodb_admin_username`: The admin's username (default 'admin') | ||
* `mongodb_admin_password`: The admin's password (default: generate a random password and store it in a file) | ||
* `mongodb_users`: A list of users to add (see example playbook below; default: []) | ||
* `mongodb_creds_dir`: The directory that should hold any generated credentials like admin (default: '.') | ||
|
||
Dependencies | ||
------------ | ||
|
||
On RedHat family distributions, this depends on the stackstorm.epel role. | ||
|
||
Example Playbook | ||
---------------- | ||
|
||
This playbook installs mongo without enabling auth or adding any users: | ||
|
||
- hosts: localhost | ||
roles: | ||
- role: StackStorm.stackstorm/roles/mongodb | ||
|
||
|
||
This playbook installs mongo, enables auth, and adds a stackstorm user, and force update the password if it already exists: | ||
|
||
- hosts: localhost | ||
roles: | ||
- role: StackStorm.stackstorm/roles/mongodb | ||
vars: | ||
mongodb_enable_auth: yes | ||
mongodb_users: | ||
- db: st2 | ||
username: st2mongo | ||
password: "{{ lookup('password', '{{ mongodb_creds_dir }}/mongodb-' + inventory_hostname + '-' + st2mongo_username + ' length=42' ) }}" | ||
roles: readWrite | ||
mongodb_force_password_update: yes | ||
|
||
Note that the `readWrite` mongo role is used by default, so `roles` can be ommitted for the above playbook. | ||
You can use the roles attribute to add any other mongo roles to your user. | ||
|
||
License | ||
------- | ||
|
||
Apache 2.0 | ||
|
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,26 @@ | ||
--- | ||
- name: "Add mongo auth user - {{ _mongodb_user.username }} on {{ _mongodb_user.db }}" | ||
mongodb_user: | ||
state: present | ||
|
||
# NOTE: on_create is idempotent, always is not. | ||
# With `update_password: on_create`, mongodb_user checks to see if the user | ||
# (a) exists on the db, and (b) has the same roles, | ||
# and then it only adds the user if it's not there or the roles have changed. | ||
# With `update_password: always`, mongodb_user cannot tell if the password | ||
# needs to be changed without attempting a login with those credentials. | ||
# But mongodb_user does not currently implement such a check. | ||
# A comment in mongodb_user points to https://jira.mongodb.org/browse/SERVER-22848 | ||
update_password: "{{ mongodb_force_update_password|ternary('always', 'on_create') }}" | ||
|
||
name: "{{ _mongodb_user.username }}" | ||
password: "{{ _mongodb_user.password }}" | ||
database: "{{ _mongodb_user.db }}" | ||
roles: "{{ _mongodb_user.roles|default('readWrite') }}" | ||
|
||
login_host: "{{ mongodb_host }}" | ||
login_port: "{{ mongodb_port }}" | ||
login_user: "{{ mongodb_admin_username }}" | ||
login_password: "{{ mongodb_admin_password }}" | ||
login_database: admin | ||
tags: [databases, mongodb] |
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
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.