@ -56,6 +56,13 @@ options:
type : str
aliases :
- login_db
autocommit :
description :
- Execute in autocommit mode when the query can ' t be run inside a transaction block
( e . g . , VACUUM ) .
- Mutually exclusive with I ( check_mode ) .
type : bool
version_added : ' 2.9 '
author :
- Felix Archambault ( @archf )
- Andrew Klychkov ( @Andersson007 )
@ -98,6 +105,12 @@ EXAMPLES = r'''
path_to_script : / var / lib / pgsql / test . sql
positional_args :
- 1
- name : Example of using autocommit parameter
postgresql_query :
db : test_db
query : VACUUM
autocommit : yes
'''
RETURN = r '''
@ -156,6 +169,7 @@ def main():
named_args = dict ( type = ' dict ' ) ,
session_role = dict ( type = ' str ' ) ,
path_to_script = dict ( type = ' path ' ) ,
autocommit = dict ( type = ' bool ' ) ,
)
module = AnsibleModule (
@ -168,6 +182,10 @@ def main():
positional_args = module . params [ " positional_args " ]
named_args = module . params [ " named_args " ]
path_to_script = module . params [ " path_to_script " ]
autocommit = module . params [ " autocommit " ]
if autocommit and module . check_mode :
module . fail_json ( msg = " Using autocommit is mutually exclusive with check_mode " )
if positional_args and named_args :
module . fail_json ( msg = " positional_args and named_args params are mutually exclusive " )
@ -182,7 +200,7 @@ def main():
module . fail_json ( msg = " Cannot read file ' %s ' : %s " % ( path_to_script , to_native ( e ) ) )
conn_params = get_conn_params ( module , module . params )
db_connection = connect_to_db ( module , conn_params , autocommit = False )
db_connection = connect_to_db ( module , conn_params , autocommit = autocommit )
cursor = db_connection . cursor ( cursor_factory = DictCursor )
# Prepare args:
@ -236,6 +254,7 @@ def main():
if module . check_mode :
db_connection . rollback ( )
else :
if not autocommit :
db_connection . commit ( )
kw = dict (