Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- mssql_script - adds ``tds_version`` and ``encryption`` parameters for pymssql (https://github.com/ansible-collections/community.general/pull/10816).
30 changes: 28 additions & 2 deletions plugins/modules/mssql_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@
type: bool
default: false
version_added: 8.4.0
encryption:
description:
- Specify whether to use encryption for the connection to the server.
Please refer to the pymssql documentation for detailed information.
type: str
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is intrinsically a boolean value, why not:

Suggested change
type: str
type: bool

?
Maybe it should have a default value, regardless of the type?

version_added: 11.4.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now:

Suggested change
version_added: 11.4.0
version_added: 12.0.0

tds_version:
description:
- Specify the TDS protocol version to use when connecting to the server.
Please refer to the pymssql documentation for detailed information.
type: str
version_added: 11.4.0
output:
description:
- With V(default) each row is returned as a list of values. See RV(query_results).
Expand Down Expand Up @@ -291,6 +303,8 @@ def run_module():
output=dict(default='default', choices=['dict', 'default']),
params=dict(type='dict'),
transaction=dict(type='bool', default=False),
tds_version=dict(type='str', required=False),
encryption=dict(type='str', required=False)
)

result = dict(
Expand All @@ -315,6 +329,9 @@ def run_module():
sql_params = module.params['params']
# Added param to set the transactional mode (true/false)
transaction = module.params['transaction']
# When connecting to lower versions such as SQL Server 2008, you can try setting tds_version to 7.0 and encryption to off.
tds_version = module.params['tds_version']
encryption = module.params['encryption']

login_querystring = login_host
if login_port != 1433:
Expand All @@ -325,8 +342,17 @@ def run_module():
msg="when supplying login_user argument, login_password must also be provided")

try:
conn = pymssql.connect(
user=login_user, password=login_password, host=login_querystring, database=db)
kwargs = {
"user": login_user,
"password": login_password,
"host": login_querystring,
"database": db,
}
if encryption is not None:
kwargs["encryption"] = encryption
if tds_version is not None:
kwargs["tds_version"] = tds_version
conn = pymssql.connect(**kwargs)
cursor = conn.cursor()
except Exception as e:
if "Unknown database" in str(e):
Expand Down