Adds a login_unix_socket option to the postgresql_db module.

pull/18777/head
Dan 10 years ago committed by Matt Clay
parent ceeeea84cd
commit 789ee410f1

@ -44,6 +44,11 @@ options:
- Host running the database - Host running the database
required: false required: false
default: localhost default: localhost
login_unix_socket:
description
- Path to a Unix domain socket for local connections
required: false
default: null
owner: owner:
description: description:
- Name of the role to set as owner of the database - Name of the role to set as owner of the database
@ -226,6 +231,7 @@ def main():
login_user=dict(default="postgres"), login_user=dict(default="postgres"),
login_password=dict(default=""), login_password=dict(default=""),
login_host=dict(default=""), login_host=dict(default=""),
login_unix_socket=dict(default=""),
port=dict(default="5432"), port=dict(default="5432"),
db=dict(required=True, aliases=['name']), db=dict(required=True, aliases=['name']),
owner=dict(default=""), owner=dict(default=""),
@ -262,6 +268,12 @@ def main():
} }
kw = dict( (params_map[k], v) for (k, v) in module.params.iteritems() kw = dict( (params_map[k], v) for (k, v) in module.params.iteritems()
if k in params_map and v != '' ) if k in params_map and v != '' )
# If a login_unix_socket is specified, incorporate it here.
is_localhost = "host" not in kw or kw["host"] == "" or kw["host"] == "localhost"
if is_localhost and module.params["login_unix_socket"] != "":
kw["host"] = module.params["login_unix_socket"]
try: try:
db_connection = psycopg2.connect(database="template1", **kw) db_connection = psycopg2.connect(database="template1", **kw)
# Enable autocommit so we can create databases # Enable autocommit so we can create databases

Loading…
Cancel
Save