Add connector name and version in the returned block

This commit is contained in:
Laurent Indermuehle 2023-01-26 14:03:28 +01:00
parent 22481ed51b
commit d6deb9bf8f
No known key found for this signature in database
GPG key ID: 93FA944C9F34DD09

View file

@ -206,6 +206,19 @@ slave_hosts:
type: dict
sample:
- { "2": { "Host": "", "Master_id": 1, "Port": 3306 } }
connector_name:
description: Name of the python connector used by the plugin. When the driver is not identified, returns C(Unknown).
returned: always
type: str
sample:
- "pymysql"
- "MySQLdb"
connector_version:
description: Version of the python connector used by the plugin. When the driver is not identified, returns C(Unknown).
returned: always
type: str
sample:
- "1.0.2"
'''
from decimal import Decimal
@ -216,6 +229,8 @@ from ansible_collections.community.mysql.plugins.module_utils.mysql import (
mysql_common_argument_spec,
mysql_driver,
mysql_driver_fail_msg,
get_driver_name,
get_driver_version,
)
from ansible.module_utils.six import iteritems
from ansible.module_utils._text import to_native
@ -558,21 +573,29 @@ def main():
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)
driver_name = get_driver_name(mysql_driver)
driver_version = get_driver_version(mysql_driver)
try:
cursor, db_conn = mysql_connect(module, login_user, login_password,
config_file, ssl_cert, ssl_key, ssl_ca, db,
check_hostname=check_hostname,
connect_timeout=connect_timeout, cursor_class='DictCursor')
except Exception as e:
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. "
"Exception message: %s" % (config_file, to_native(e)))
msg = ('unable to connect to database using %s %s, check login_user '
'and login_password are correct or %s has the credentials. '
'Exception message: %s' % (driver_name, driver_version, config_file, to_native(e)))
module.fail_json(msg)
###############################
# Create object and do main job
mysql = MySQL_Info(module, cursor)
module.exit_json(changed=False, **mysql.get_info(filter_, exclude_fields, return_empty_dbs))
module.exit_json(changed=False,
connector_name=driver_name,
connector_version=driver_version,
**mysql.get_info(filter_, exclude_fields, return_empty_dbs))
if __name__ == '__main__':