#364 Added support for update_password=dict(default="always", choices=["always", "on_create"])
This commit is contained in:
parent
62a7742481
commit
d1c68eea9f
1 changed files with 15 additions and 2 deletions
|
@ -87,6 +87,14 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: present
|
default: present
|
||||||
choices: [ "present", "absent" ]
|
choices: [ "present", "absent" ]
|
||||||
|
update_password:
|
||||||
|
required: false
|
||||||
|
default: always
|
||||||
|
choices: ['always', 'on_create']
|
||||||
|
version_added: "2.1"
|
||||||
|
description:
|
||||||
|
- C(always) will update passwords if they differ. C(on_create) will only set the password for newly created users.
|
||||||
|
|
||||||
notes:
|
notes:
|
||||||
- Requires the pymongo Python package on the remote host, version 2.4.2+. This
|
- 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
|
can be installed using pip or the OS package manager. @see http://api.mongodb.org/python/current/installation.html
|
||||||
|
@ -196,6 +204,7 @@ def main():
|
||||||
ssl=dict(default=False),
|
ssl=dict(default=False),
|
||||||
roles=dict(default=None, type='list'),
|
roles=dict(default=None, type='list'),
|
||||||
state=dict(default='present', choices=['absent', 'present']),
|
state=dict(default='present', choices=['absent', 'present']),
|
||||||
|
update_password=dict(default="always", choices=["always", "on_create"]),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -213,6 +222,7 @@ def main():
|
||||||
ssl = module.params['ssl']
|
ssl = module.params['ssl']
|
||||||
roles = module.params['roles']
|
roles = module.params['roles']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
update_password = module.params['update_password']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if replica_set:
|
if replica_set:
|
||||||
|
@ -239,8 +249,11 @@ def main():
|
||||||
module.fail_json(msg='unable to connect to database: %s' % str(e))
|
module.fail_json(msg='unable to connect to database: %s' % str(e))
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
if password is None:
|
if password is None and update_password == 'always':
|
||||||
module.fail_json(msg='password parameter required when adding a user')
|
module.fail_json(msg='password parameter required when adding a user unless update_password is set to on_create')
|
||||||
|
|
||||||
|
if update_password != 'always' and user_find(client, user):
|
||||||
|
password = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_add(module, client, db_name, user, password, roles)
|
user_add(module, client, db_name, user, password, roles)
|
||||||
|
|
Loading…
Reference in a new issue