| 1 |
# MongoDB Version and PyMongoDB Version Compatibility |
| 2 |
|
| 3 |
- This collection is tested against at least the most recent two MongoDB releases. |
| 4 |
- PyMongo - latest version supported only. |
| 5 |
- Please upgrade your PyMongo driver version if you encounter difficulties. |
| 6 |
|
| 7 |
# Mongodb Collection |
| 8 |
|Category|Status| |
| 9 |
|---|---| |
| 10 |
|Github CI|| |
| 11 |
|Codecov|[](https://codecov.io/gh/ansible-collections/community.mongodb)| |
| 12 |
|CI Roles|| |
| 13 |
|Latest Build|| |
| 14 |
|
| 15 |
This collection called `mongodb` aims at providing all Ansible modules allowing to interact with MongoDB. |
| 16 |
The modules present in Ansible 2.9 are included in this collection and will benefit from the evolutions and quality requirements from this collection. |
| 17 |
|
| 18 |
As this is an independent collection, it can be released on its own release cadence. |
| 19 |
|
| 20 |
If you like this collection please give us a rating on [Ansible Galaxy](https://galaxy.ansible.com/community/mongodb). |
| 21 |
|
| 22 |
## Communication |
| 23 |
|
| 24 |
* Join the Ansible forum: |
| 25 |
* [Get Help](https://forum.ansible.com/c/help/6): get help or help others. |
| 26 |
* [Posts tagged with 'mongodb'](https://forum.ansible.com/tag/mongodb): subscribe to participate in collection-related conversations. |
| 27 |
* [Social Spaces](https://forum.ansible.com/c/chat/4): gather and interact with fellow enthusiasts. |
| 28 |
* [News & Announcements](https://forum.ansible.com/c/news/5): track project-wide announcements including social events. |
| 29 |
|
| 30 |
* The Ansible [Bullhorn newsletter](https://docs.ansible.com/ansible/devel/community/communication.html#the-bullhorn): used to announce releases and important changes. |
| 31 |
|
| 32 |
For more information about communication, see the [Ansible communication guide](https://docs.ansible.com/ansible/devel/community/communication.html). |
| 33 |
|
| 34 |
## Collection contents |
| 35 |
|
| 36 |
### Roles |
| 37 |
|
| 38 |
These roles prepare servers with Debian-based and RHEL-based distributions to run MongoDB. These roles should not be used to manage MongoDB instances that have been previously installed or configured through other means. |
| 39 |
|
| 40 |
- `community.mongodb.mongodb_linux`: A simple role to configure Linux Operating System settings, as advised in the [MongoDB Production Notes](https://docs.mongodb.com/manual/administration/production-notes/). |
| 41 |
- `community.mongodb.mongodb_selinux`: Configure SELinux for MongoDB. |
| 42 |
|
| 43 |
- `community.mongodb.mongodb_repository`: Configures a package repository for MongoDB on Debian and RedHat based platforms. |
| 44 |
- `community.mongodb.mongodb_install`: Install MongoDB packages on Debian and RedHat based platforms. This role, unlike all other roles, provides for installing specific versions of mongodb-org packages. Other roles merely validate that mongodb-org is installed/present; they do not install particular versions. |
| 45 |
|
| 46 |
These roles manage configuring and starting various MongoDB services. |
| 47 |
|
| 48 |
- `community.mongodb.mongodb_mongod`: Configure the `mongod` service (includes populating `mongod.conf`) which is a MongoDB replicaset or standalone server. |
| 49 |
- `community.mongodb.mongodb_mongos`: Configure the `mongos` service (includes populating `mongos.conf`) which only runs in a sharded MongoDB cluster. |
| 50 |
- `community.mongodb.mongodb_config`: Configure the CSRS Config Server Replicaset for a MongoDB sharded cluster. The CSRS is a special-purpose instance of `mongod` that hosts the `config` database for the sharded cluster. For standalone installations, please use the `mongodb_mongod` role instead. |
| 51 |
- `community.mongodb.mongodb_auth`: Configure auth on MongoDB servers. NB: The other MongoDB server config roles (`mongodb_mongod`, `mongodb_mongos`, `mongodb_config`) do not configure auth. Use this role in conjunction with the other roles. |
| 52 |
|
| 53 |
### Plugins |
| 54 |
|
| 55 |
#### Lookup Plugins |
| 56 |
- `community.mongodb.mongodb`: A lookup plugin that gets info from a collection using the MongoDB `find()` function. |
| 57 |
|
| 58 |
#### Cache Plugins |
| 59 |
- `community.mongodb.mongodb`: A cache plugin that stores the host fact cache records in MongoDB. |
| 60 |
|
| 61 |
#### Modules |
| 62 |
|
| 63 |
These modules are for any MongoDB cluster (standalone, replicaset, or sharded): |
| 64 |
|
| 65 |
- `community.mongodb.mongodb_index`: Creates or drops indexes on MongoDB collections. |
| 66 |
- `community.mongodb.mongodb_info`: Gather information about MongoDB instance. |
| 67 |
- `community.mongodb.mongodb_oplog`: [Resizes](https://docs.mongodb.com/manual/tutorial/change-oplog-size) the MongoDB oplog (MongoDB 3.6+ only). |
| 68 |
- `community.mongodb.mongodb_parameter`: Change an administrative parameter on a MongoDB server. |
| 69 |
- `community.mongodb.mongodb_role`: Manage [MongoDB Roles](https://www.mongodb.com/docs/upcoming/tutorial/manage-users-and-roles/). |
| 70 |
- `community.mongodb.mongodb_schema`: Manages MongoDB Document Schema Validators. |
| 71 |
- `community.mongodb.mongodb_shell`: Run commands via the MongoDB shell. |
| 72 |
- `community.mongodb.mongodb_shutdown`: Cleans up all database resources and then terminates the mongod/mongos process. |
| 73 |
- `community.mongodb.mongodb_user`: Adds or removes a user from a MongoDB database. |
| 74 |
|
| 75 |
These modules are only useful for replicaset (or sharded) MongoDB clusters: |
| 76 |
|
| 77 |
- `community.mongodb.mongodb_maintenance`: Enables or disables [maintenance](https://docs.mongodb.com/manual/reference/command/replSetMaintenance/) mode for a secondary member. |
| 78 |
- `community.mongodb.mongodb_replicaset`: Initialises a MongoDB replicaset. |
| 79 |
- `community.mongodb.mongodb_status`: Validates the status of the replicaset. |
| 80 |
- `community.mongodb.mongodb_stepdown`: [Step down](https://docs.mongodb.com/manual/reference/command/replSetStepDown/) the MongoDB node from a PRIMARY state. |
| 81 |
|
| 82 |
These modules are only useful for sharded MongoDB clusters: |
| 83 |
|
| 84 |
- `community.mongodb.mongodb_balancer`: Manages the MongoDB Sharded Cluster Balancer. |
| 85 |
- `community.mongodb.mongodb_shard`: Add or remove shards from a MongoDB Cluster. |
| 86 |
- `community.mongodb.mongodb_shard_tag`: Manage Shard Tags. |
| 87 |
- `community.mongodb.mongodb_shard_zone`: Manage Shard Zones. |
| 88 |
|
| 89 |
These modules are only useful for MongoDB Atlas clusters: |
| 90 |
|
| 91 |
- `community.mongodb.mongodb_atlas_cluster`: Manage MongoDB clusters in Atlas. |
| 92 |
- `community.mongodb.mongodb_atlas_ldap_user`: Manage LDAP users in Atlas. |
| 93 |
- `community.mongodb.mongodb_atlas_user`: Manage users in Atlas. |
| 94 |
- `community.mongodb.mongodb_atlas_whitelist`: Manage IP whitelists in Atlas. |
| 95 |
|
| 96 |
## community.mongodb Role Tags |
| 97 |
|
| 98 |
### General role tags |
| 99 |
|
| 100 |
These tags are applicable across all roles. |
| 101 |
|
| 102 |
|tags|comment| |
| 103 |
|----|-------| |
| 104 |
|mongodb|Tasks specific to MongoDB.| |
| 105 |
|debian|Tasks specific to Debian Family Operating Systems.| |
| 106 |
|redhat|Tasks specific to RedHat Family Operating Systems.| |
| 107 |
|pip|Tasks working with pip.| |
| 108 |
|vars|Tasks that load variables.| |
| 109 |
|pkg|Tasks that install packages.| |
| 110 |
|debug|Tasks that output debugging info.| |
| 111 |
|service|Tasks dealing with system services.| |
| 112 |
|setup|Tasks that are mainly executed during initial deployment.| |
| 113 |
|ci|Tasks that are specific to the community.mongodb CI code.| |
| 114 |
|linux|Tasks affecting Linux OS settings.| |
| 115 |
|
| 116 |
### Role Specific Tags |
| 117 |
|
| 118 |
These tags apply to the specific roles as indicated. |
| 119 |
|
| 120 |
|role|tag|comment| |
| 121 |
|----|---|-------| |
| 122 |
|mongodb_auth|admin_user|Tasks that work with the MongoDB Administrator user.| |
| 123 |
|mongodb_auth|app_user|Tasks that work with MongoDB app users.| |
| 124 |
|
| 125 |
## Usage Examples |
| 126 |
|
| 127 |
The following links provide various examples for how the community.mongodb roles and modules can be used in real projects. |
| 128 |
|
| 129 |
* https://github.com/rhysmeister/AutomatingMongoDBWithAnsible (no longer maintained) |
| 130 |
* https://github.com/superset1/Ansible_role_mongodb |
| 131 |
* https://github.com/ansible-collections/community.mongodb/tree/master/roles/ROLENAME/molecule (replace ROLENAME, some full examples that we use in our testing) |
| 132 |
|
| 133 |
## Running the integration and unit tests |
| 134 |
|
| 135 |
* Requirements |
| 136 |
* [Python 3.5+](https://www.python.org/) |
| 137 |
* [pip](https://pypi.org/project/pip/) |
| 138 |
* [virtualenv](https://virtualenv.pypa.io/en/latest/) or [pipenv](https://pypi.org/project/pipenv/) if you prefer. |
| 139 |
* [git](https://git-scm.com/) |
| 140 |
* [docker](https://www.docker.com/) |
| 141 |
|
| 142 |
* Useful Links |
| 143 |
* [Pip & Virtual Environments](https://docs.python-guide.org/dev/virtualenvs/) |
| 144 |
* [Ansible Integration Tests](https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html) |
| 145 |
|
| 146 |
The ansible-test tool requires a specific directory hierarchy to function correctly so please follow carefully. |
| 147 |
|
| 148 |
* Create the required directory structure. N-B. The ansible-test tool requires this format. |
| 149 |
|
| 150 |
```bash |
| 151 |
mkdir -p git/ansible_collections/community |
| 152 |
cd git/ansible_collections/community |
| 153 |
``` |
| 154 |
|
| 155 |
* Clone the required projects. |
| 156 |
|
| 157 |
```bash |
| 158 |
git clone https://github.com/ansible-collections/community.mongodb.git ./mongodb |
| 159 |
git clone https://github.com/ansible-collections/community.general.git ./general |
| 160 |
git clone https://github.com/ansible-collections/community.crypto.git ./crypto |
| 161 |
``` |
| 162 |
|
| 163 |
* Create and activate a virtual environment. |
| 164 |
|
| 165 |
```bash |
| 166 |
virtualenv venv |
| 167 |
source venv/bin/activate |
| 168 |
``` |
| 169 |
|
| 170 |
* Change to the project directory. |
| 171 |
|
| 172 |
```bash |
| 173 |
cd mongodb |
| 174 |
``` |
| 175 |
|
| 176 |
* Install the devel branch of ansible-base. |
| 177 |
|
| 178 |
```bash |
| 179 |
pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check |
| 180 |
``` |
| 181 |
|
| 182 |
* Run integration tests for the mongodb_shard module. |
| 183 |
|
| 184 |
```bash |
| 185 |
ansible-test integration --docker default -v --color --python 3.6 mongodb_shard |
| 186 |
``` |
| 187 |
|
| 188 |
* Run integration tests for the mongodb_status module. |
| 189 |
|
| 190 |
```bash |
| 191 |
ansible-test integration --docker default -v --color --python 3.6 mongodb_status |
| 192 |
``` |
| 193 |
|
| 194 |
* Run integration tests for the mongodb_oplog module. |
| 195 |
|
| 196 |
```bash |
| 197 |
ansible-test integration --docker ubuntu1804 -v --color --python 3.6 mongodb_oplog |
| 198 |
``` |
| 199 |
|
| 200 |
* Run tests for everything in the collection. |
| 201 |
|
| 202 |
```bash |
| 203 |
ansible-test integration --docker default -v --color --python 3.6 |
| 204 |
``` |
| 205 |
|
| 206 |
* Run the units tests |
| 207 |
|
| 208 |
```bash |
| 209 |
ansible-test units --docker default -v --color --python 3.6 |
| 210 |
``` |
| 211 |
|
| 212 |
## Release Notes |
| 213 |
|
| 214 |
Needs improvement but the general process for issuing a new release to Ansible Galaxy is as follows... |
| 215 |
|
| 216 |
- View commits since last release and copy text for release notes |
| 217 |
|
| 218 |
```bash |
| 219 |
git log 1.3.0..HEAD |
| 220 |
git log 1.3.0..HEAD --oneline |
| 221 |
``` |
| 222 |
|
| 223 |
- Create a new branch |
| 224 |
- Update galaxy.yml with version and any other appropriate info |
| 225 |
- Update changelogs/changelog.yaml |
| 226 |
- Update CHANGELOG.rst |
| 227 |
- Create a pull request |
| 228 |
- Review and merge when happy |
| 229 |
- Tag release on the master branch |
| 230 |
|
| 231 |
```bash |
| 232 |
git tag <release> |
| 233 |
git push --tags |
| 234 |
``` |
| 235 |
|
| 236 |
Automation will bundle the release and push to Galaxy. Should take around 10-15 minutes. |
| 237 |
|
| 238 |
## GitHub workflow |
| 239 |
|
| 240 |
* Maintainers would be members of this GitHub Repo |
| 241 |
* Branch protections could be used to enforce 1 (or 2) reviews from relevant maintainers [CODEOWNERS](.github/CODEOWNERS) |
| 242 |
|
| 243 |
## Contributing |
| 244 |
|
| 245 |
Any contribution is welcome and we only ask contributors to: |
| 246 |
* Provide *at least* integration tests for any contribution. |
| 247 |
* Create an issue for any significant contribution that would change a large portion of the codebase. |
| 248 |
* Unless there's a very good reason for it, i.e. it's a bug, we aim not to change default behaviour. |
| 249 |
|
| 250 |
## Stargazers over time |
| 251 |
|
| 252 |
[](https://starchart.cc/ansible-collections/community.mongodb) |
| 253 |
|
| 254 |
## License |
| 255 |
|
| 256 |
GNU General Public License v3.0 or later |
| 257 |
|
| 258 |
See LICENSING to see the full text. |