Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
aaaf9dbc
Commit
aaaf9dbc
authored
Mar 16, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5597 from laggyluke/mongodb_user_idempotence
Fix idempotence in mongodb_user module
parents
e4fcc434
66b2d55a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
12 deletions
+21
-12
library/database/mongodb_user
+21
-12
No files found.
library/database/mongodb_user
View file @
aaaf9dbc
...
...
@@ -188,19 +188,28 @@ def main():
try
:
client
=
MongoClient
(
login_host
,
int
(
login_port
))
if
login_user
is
None
and
login_password
is
None
:
mongocnf_creds
=
load_mongocnf
()
if
mongocnf_creds
is
not
False
:
login_user
=
mongocnf_creds
[
'user'
]
login_password
=
mongocnf_creds
[
'password'
]
elif
login_password
is
None
and
login_user
is
not
None
:
module
.
fail_json
(
msg
=
'when supplying login arguments, both login_user and login_password must be provided'
)
if
login_user
is
not
None
and
login_password
is
not
None
:
client
.
admin
.
authenticate
(
login_user
,
login_password
)
except
ConnectionFailure
,
e
:
module
.
fail_json
(
msg
=
'unable to connect to database, check login_user and login_password are correct'
)
module
.
fail_json
(
msg
=
'unable to connect to database, check login_host and login_port are correct'
)
# try to authenticate as a target user to check if it already exists
try
:
client
[
db_name
]
.
authenticate
(
user
,
password
)
if
state
==
'present'
:
module
.
exit_json
(
changed
=
False
,
user
=
user
)
except
OperationFailure
:
if
state
==
'absent'
:
module
.
exit_json
(
changed
=
False
,
user
=
user
)
if
login_user
is
None
and
login_password
is
None
:
mongocnf_creds
=
load_mongocnf
()
if
mongocnf_creds
is
not
False
:
login_user
=
mongocnf_creds
[
'user'
]
login_password
=
mongocnf_creds
[
'password'
]
elif
login_password
is
None
and
login_user
is
not
None
:
module
.
fail_json
(
msg
=
'when supplying login arguments, both login_user and login_password must be provided'
)
if
login_user
is
not
None
and
login_password
is
not
None
:
client
.
admin
.
authenticate
(
login_user
,
login_password
)
if
state
==
'present'
:
if
password
is
None
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment