Author: | Elliott Foster |
---|
parameter | required | default | choices | comments |
---|---|---|---|---|
database | yes | The name of the database to add/remove the user from | ||
login_host | no | localhost | The host running the database | |
login_password | no | The password used to authenticate with | ||
login_port | no | 27017 | The port to connect to | |
login_user | no | The username used to authenticate with | ||
password | no | The password to use for the user | ||
replica_set | no | Replica set to connect to (automatically connects to primary for writes) (added in Ansible 1.6) | ||
roles | no | readWrite | The database user roles valid values are one or more of the following: read, 'readWrite', 'dbAdmin', 'userAdmin', 'clusterAdmin', 'readAnyDatabase', 'readWriteAnyDatabase', 'userAdminAnyDatabase', 'dbAdminAnyDatabase'This param requires mongodb 2.4+ and pymongo 2.5+ (added in Ansible 1.3) | |
state | no | present |
|
The database user state |
user | yes | The name of the user to add or remove |
Note
Requires pymongo
# Create 'burgers' database user with name 'bob' and password '12345'.
- mongodb_user: database=burgers name=bob password=12345 state=present
# Delete 'burgers' database user with name 'bob'.
- mongodb_user: database=burgers name=bob state=absent
# Define more users with various specific roles (if not defined, no roles is assigned, and the user will be added via pre mongo 2.2 style)
- mongodb_user: database=burgers name=ben password=12345 roles='read' state=present
- mongodb_user: database=burgers name=jim password=12345 roles='readWrite,dbAdmin,userAdmin' state=present
- mongodb_user: database=burgers name=joe password=12345 roles='readWriteAnyDatabase' state=present
# add a user to database in a replica set, the primary server is automatically discovered and written to
- mongodb_user: database=burgers name=bob replica_set=blecher password=12345 roles='readWriteAnyDatabase' state=present
Note
Requires the pymongo Python package on the remote host, version 2.4.2+. This can be installed using pip or the OS package manager. @see http://api.mongodb.org/python/current/installation.html