mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix using postgres default values
When initalizing a connection to psycopg2, in order to use the default values, the keywords must be missing. So we use a dictionary as a kwarg and include only the keywords that do not have an empty value on the module parameters.
This commit is contained in:
parent
7d50a5c2b7
commit
95fc5dd4a8
1 changed files with 12 additions and 4 deletions
|
@ -75,11 +75,19 @@ def main():
|
||||||
encoding = module.params["encoding"]
|
encoding = module.params["encoding"]
|
||||||
state = module.params["state"]
|
state = module.params["state"]
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
|
# 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:
|
try:
|
||||||
db_connection = psycopg2.connect(host=module.params["login_host"],
|
db_connection = psycopg2.connect(database="template1", **kw)
|
||||||
user=module.params["login_user"],
|
|
||||||
password=module.params["login_password"],
|
|
||||||
database="template1")
|
|
||||||
# Enable autocommit so we can create databases
|
# Enable autocommit so we can create databases
|
||||||
db_connection.autocommit = True
|
db_connection.autocommit = True
|
||||||
cursor = db_connection.cursor()
|
cursor = db_connection.cursor()
|
||||||
|
|
Loading…
Add table
Reference in a new issue