Skip to content

Conversation

@Halo1236
Copy link

@Halo1236 Halo1236 commented Sep 12, 2025

SUMMARY

This pull request adds support for specifying tds_version and encryption options when connecting to Microsoft SQL Server in the mssql_script Ansible module. These options improve compatibility with older SQL Server versions and allow more flexible connection configurations.

Connection options enhancements:

  • Added two new module parameters, tds_version and encryption, to allow users to specify the TDS protocol version and encryption settings for SQL Server connections.
  • Updated the connection logic to pass the tds_version and encryption parameters to pymssql.connect, enabling these options to be used when establishing the database connection. [1] [2]
ISSUE TYPE
  • Bugfix Pull Reques
COMPONENT NAME

mssql_script

@ansibullbot
Copy link
Collaborator

cc @kbudde
click here for bot help

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module new_contributor Help guide this first time contributor plugins plugin (any type) labels Sep 12, 2025
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Sep 12, 2025
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-11 Automatically create a backport for the stable-10 branch labels Sep 12, 2025
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

I don't think this is related to #5693 though. Why do you think it is?

@felixfontein
Copy link
Collaborator

Also, please add a changelog fragment. Thanks.

@felixfontein felixfontein changed the title Add additional parameters to support connections to lower versions of… mssql_script: add tds_version and encryption parameters Sep 13, 2025
@Halo1236
Copy link
Author

@felixfontein Thank you for your guidance! I have updated the code and the changelog. There is an issue in Issues that has the same error message as the one I encountered during my testing, but I am not sure if my update can resolve their problem. Therefore, I have removed the association for now.

@ansibullbot ansibullbot removed ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Sep 16, 2025
@Halo1236 Halo1236 force-pushed the fix_2008_SQLServer_error branch from 07a35a6 to 0266b75 Compare September 17, 2025 07:50
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

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

Hi @Halo1236 thanks for your contribution!

I've left a couple of comments, nothing major. Other than that, it LGTM

@ansibullbot ansibullbot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI labels Sep 18, 2025
@ansibullbot
Copy link
Collaborator

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

plugins/modules/mssql_script.py:179:1: W293: blank line contains whitespace

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

plugins/modules/mssql_script.py:179:1: W293: blank line contains whitespace

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

plugins/modules/mssql_script.py:179:1: W293: blank line contains whitespace

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

plugins/modules/mssql_script.py:179:1: W293: blank line contains whitespace

click here for bot help

@ansibullbot ansibullbot added the ci_verified Push fixes to PR branch to re-run CI label Sep 18, 2025
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"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- The available values are "off" and "on"
- The available values are V("off") and V("on").

(I left the quotes to avoid conversion to booleans.)

If no other values are allowed, how about adding choices to limit the input to these two values?

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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- The available values are "7.0", "7.1", "7.2", "7.3", "7.4", "8.0" etc.
- The available values are V(7.0), V(7.1), V(7.2), V(7.3), V(7.4), V(8.0), and so on.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

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

Hi @Halo1236 , thanks for your contribution.

Couple of comments.

- 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
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?

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

login_port: "{{ mssql_port }}"
db: master
tds_version: "7.0"
encryption: off
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
encryption: off
encryption: false

@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Oct 2, 2025
@felixfontein felixfontein removed the backport-11 Automatically create a backport for the stable-10 branch label Oct 13, 2025
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

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

Hi @Halo1236

A couple of additional comments. The PR is looking good, it just need these few adjustments.

If you are struggling with the tests, may I suggest giving a try to andebox, by yours truly:

https://pypi.org/project/andebox/

You can run this sanity test easily in your local machine by simply running:

$ andebox test -- sanity --docker default --python 3.13 plugins/modules/your_module.py

Please refer to the pymssql documentation for detailed information.
- The available values are "off" and "on"
type: str
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

params=dict(type='dict'),
transaction=dict(type='bool', default=False),
tds_version=dict(type='str'),
encryption=dict(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.

Just making life better for the next person:

Suggested change
encryption=dict(type='str')
encryption=dict(type='str'),

"database": db,
}
if encryption is not None:
connection_args["encryption"] = encryption
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
connection_args["encryption"] = encryption
connection_args["encryption"] = "on" if encryption else "off"

- 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
Copy link
Collaborator

@russoz russoz Oct 26, 2025

Choose a reason for hiding this comment

The 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue/PR relates to a bug check-before-release PR will be looked at again shortly before release and merged if possible. ci_verified Push fixes to PR branch to re-run CI module module needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) stale_ci CI is older than 7 days, rerun before merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants