-
Notifications
You must be signed in to change notification settings - Fork 1.7k
mssql_script: add tds_version and encryption parameters #10816
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
base: main
Are you sure you want to change the base?
Changes from all commits
2643137
fafd6ee
0266b75
c19bff1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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). |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -62,6 +62,20 @@ | |||||
| 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. | ||||||
| - The available values are "off" and "on" | ||||||
| type: str | ||||||
Halo1236 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that this is intrinsically a boolean value, why not:
Suggested change
? |
||||||
| version_added: 11.4.0 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now:
Suggested change
|
||||||
| tds_version: | ||||||
Halo1236 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| description: | ||||||
| - Specify the TDS protocol version to use when connecting to the server. | ||||||
| Please refer to the pymssql documentation for detailed information. | ||||||
| - The available values are "7.0", "7.1", "7.2", "7.3", "7.4", "8.0" etc. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The param is type=str, the doc should recommend wrapping quotes, so that the values are not converted to float. |
||||||
| type: str | ||||||
Halo1236 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| version_added: 11.4.0 | ||||||
| output: | ||||||
| description: | ||||||
| - With V(default) each row is returned as a list of values. See RV(query_results). | ||||||
|
|
@@ -162,6 +176,18 @@ | |||||
| - result_batches_dict.query_results_dict[0] | length == 2 # two selects in first batch | ||||||
| - result_batches_dict.query_results_dict[0][0] | length == 1 # one row in first select | ||||||
| - result_batches_dict.query_results_dict[0][0][0]['b0s0'] == 'Batch 0 - Select 0' # column 'b0s0' of first row | ||||||
|
|
||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is tripping the sanity test (trailing spaces in the line):
Suggested change
|
||||||
| - name: Get lower version DB information | ||||||
| community.general.mssql_script: | ||||||
| login_user: "{{ mssql_login_user }}" | ||||||
| login_password: "{{ mssql_login_password }}" | ||||||
| login_host: "{{ mssql_host }}" | ||||||
| login_port: "{{ mssql_port }}" | ||||||
| db: master | ||||||
| tds_version: "7.0" | ||||||
| encryption: off | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the param type=str, this should have quotes around the value. If you change it to type=bool, then
Suggested change
|
||||||
| script: | | ||||||
| SELECT @@version | ||||||
| """ | ||||||
|
|
||||||
| RETURN = r""" | ||||||
|
|
@@ -291,6 +317,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'), | ||||||
| encryption=dict(type='str') | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just making life better for the next person:
Suggested change
|
||||||
| ) | ||||||
|
|
||||||
| result = dict( | ||||||
|
|
@@ -315,6 +343,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: | ||||||
|
|
@@ -325,8 +356,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) | ||||||
| connection_args = { | ||||||
| "user": login_user, | ||||||
| "password": login_password, | ||||||
| "host": login_querystring, | ||||||
| "database": db, | ||||||
| } | ||||||
| if encryption is not None: | ||||||
| connection_args["encryption"] = encryption | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you make the parameter a boolean, then this should go:
Suggested change
|
||||||
| if tds_version is not None: | ||||||
| connection_args["tds_version"] = tds_version | ||||||
| conn = pymssql.connect(**connection_args) | ||||||
| cursor = conn.cursor() | ||||||
| except Exception as e: | ||||||
| if "Unknown database" in str(e): | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I left the quotes to avoid conversion to booleans.)
If no other values are allowed, how about adding
choicesto limit the input to these two values?