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
aebae13c
Commit
aebae13c
authored
Dec 31, 2013
by
Jinn Koriech
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
postgresql_user module: Gracefully handle ALTER ROLE on read-only postgres servers.
parent
99616d0c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
3 deletions
+13
-3
library/database/postgresql_user
+13
-3
No files found.
library/database/postgresql_user
View file @
aebae13c
...
...
@@ -173,7 +173,7 @@ def user_add(cursor, user, password, role_attr_flags, encrypted, expires):
cursor
.
execute
(
query
)
return
True
def
user_alter
(
cursor
,
user
,
password
,
role_attr_flags
,
encrypted
,
expires
):
def
user_alter
(
cursor
,
module
,
user
,
password
,
role_attr_flags
,
encrypted
,
expires
):
"""Change user password and/or attributes. Return True if changed, False otherwise."""
changed
=
False
...
...
@@ -203,7 +203,17 @@ def user_alter(cursor, user, password, role_attr_flags, encrypted, expires):
if
expires
is
not
None
:
alter
=
alter
+
" VALID UNTIL '
%(expires)
s'"
%
{
"exipres"
:
expires
}
cursor
.
execute
(
alter
)
try
:
cursor
.
execute
(
alter
)
except
psycopg2
.
InternalError
,
e
:
if
e
.
pgcode
==
'25006'
:
# Handle errors due to read-only transactions indicated by pgcode 25006
# ERROR: cannot execute ALTER ROLE in a read-only transaction
changed
=
False
module
.
fail_json
(
msg
=
e
.
pgerror
)
return
changed
else
:
raise
psycopg2
.
InternalError
,
e
# Grab new role attributes.
cursor
.
execute
(
select
,
{
"user"
:
user
})
...
...
@@ -455,7 +465,7 @@ def main():
if
state
==
"present"
:
if
user_exists
(
cursor
,
user
):
changed
=
user_alter
(
cursor
,
user
,
password
,
role_attr_flags
,
encrypted
,
expires
)
changed
=
user_alter
(
cursor
,
module
,
user
,
password
,
role_attr_flags
,
encrypted
,
expires
)
else
:
changed
=
user_add
(
cursor
,
user
,
password
,
role_attr_flags
,
encrypted
,
expires
)
changed
=
grant_privileges
(
cursor
,
user
,
privs
)
or
changed
...
...
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