Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for postgresql_user to make it work with postgresql defaults and under Python 2.4 #898

Merged
merged 1 commit into from
Aug 18, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions library/postgresql_user
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,21 @@ def main():

if not postgresqldb_found:
module.fail_json(msg="the python psycopg2 module is required")


# To use defaults values, keyword arguments must be absent, so
# check which values are empty and don't include in the **kw
# dictionary
params_map = {
"login_host":"host",
"login_user":"user",
"login_password":"password"
}
kw = dict( (params_map[k], v) for (k, v) in module.params.iteritems()
if k in params_map and v != "" )
try:
db_connection = psycopg2.connect(host=module.params["login_host"],
user=module.params["login_user"],
password=module.params["login_password"],
database=db)
db_connection = psycopg2.connect(database=db, **kw)
cursor = db_connection.cursor()
except Exception as e:
except Exception, e:
module.fail_json(msg="unable to connect to database: %s" % e)

if state == "present":
Expand Down