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
1b73227a
Commit
1b73227a
authored
Feb 18, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2128 from lorin/postgres-public
postgresql_user: Add support for PUBLIC
parents
7f9bb908
eac339e9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
2 deletions
+22
-2
library/postgresql_user
+22
-2
No files found.
library/postgresql_user
View file @
1b73227a
...
...
@@ -110,6 +110,9 @@ notes:
PostgreSQL must also be installed on the remote host. For Ubuntu-based
systems, install the postgresql, libpq-dev, and python-psycopg2 packages
on the remote host before using this module.
- If you specify PUBLIC as the user, then the privilege changes will apply
to all users. You may not specify password or role_attr_flags when the
PUBLIC user is specified.
requirements: [ psycopg2 ]
author: Lorin Hochstein
'''
...
...
@@ -129,6 +132,9 @@ else:
def
user_exists
(
cursor
,
user
):
# The PUBLIC user is a special case that is always there
if
user
==
'PUBLIC'
:
return
True
query
=
"SELECT rolname FROM pg_roles WHERE rolname=
%(user)
s"
cursor
.
execute
(
query
,
{
'user'
:
user
})
return
cursor
.
rowcount
>
0
...
...
@@ -144,6 +150,14 @@ def user_alter(cursor, user, password, role_attr_flags):
"""Change user password"""
changed
=
False
if
user
==
'PUBLIC'
:
if
password
is
not
None
:
module
.
fail_json
(
msg
=
"cannot change the password for PUBLIC user"
)
elif
role_attr_flags
!=
''
:
module
.
fail_json
(
msg
=
"cannot change the role_attr_flags for PUBLIC user"
)
else
:
return
False
# Handle passwords.
if
password
is
not
None
or
role_attr_flags
is
not
None
:
# Select password and all flag-like columns in order to verify changes.
...
...
@@ -241,14 +255,20 @@ def has_database_privilege(cursor, user, db, priv):
def
grant_database_privilege
(
cursor
,
user
,
db
,
priv
):
prev_priv
=
get_database_privileges
(
cursor
,
user
,
db
)
query
=
'GRANT
%
s ON DATABASE
\"
%
s
\"
TO
\"
%
s
\"
'
%
(
priv
,
db
,
user
)
if
user
==
"PUBLIC"
:
query
=
'GRANT
%
s ON DATABASE
\"
%
s
\"
TO PUBLIC'
%
(
priv
,
db
)
else
:
query
=
'GRANT
%
s ON DATABASE
\"
%
s
\"
TO
\"
%
s
\"
'
%
(
priv
,
db
,
user
)
cursor
.
execute
(
query
)
curr_priv
=
get_database_privileges
(
cursor
,
user
,
db
)
return
len
(
curr_priv
)
>
len
(
prev_priv
)
def
revoke_database_privilege
(
cursor
,
user
,
db
,
priv
):
prev_priv
=
get_database_privileges
(
cursor
,
user
,
db
)
query
=
'REVOKE
%
s ON DATABASE
\"
%
s
\"
FROM
\"
%
s
\"
'
%
(
priv
,
db
,
user
)
if
user
==
"PUBLIC"
:
query
=
'REVOKE
%
s ON DATABASE
\"
%
s
\"
FROM PUBLIC'
%
(
priv
,
db
)
else
:
query
=
'REVOKE
%
s ON DATABASE
\"
%
s
\"
FROM
\"
%
s
\"
'
%
(
priv
,
db
,
user
)
cursor
.
execute
(
query
)
curr_priv
=
get_database_privileges
(
cursor
,
user
,
db
)
return
len
(
curr_priv
)
<
len
(
prev_priv
)
...
...
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