diff --git a/changelogs/fragments/7267-redis_info.yml b/changelogs/fragments/7267-redis_info.yml new file mode 100644 index 00000000000..9b56efa98c6 --- /dev/null +++ b/changelogs/fragments/7267-redis_info.yml @@ -0,0 +1,2 @@ +minor_changes: + - redis_info - Refactor the redis_info module to use the redis module_utils enabling to pass TLS parameters to the Redis client. diff --git a/plugins/modules/redis_info.py b/plugins/modules/redis_info.py index b9900a7caf3..057f166bef8 100644 --- a/plugins/modules/redis_info.py +++ b/plugins/modules/redis_info.py @@ -34,6 +34,20 @@ description: - The password used to authenticate with, when authentication is enabled for the Redis server. type: str + tls: + description: + - Establish a secure TLS connection. + type: bool + default: false + ca_certs: + description: + - CA Certificate file to verify with. + type: str + validate_certs: + description: + - Validate the SSL server certificate. + type: bool + default: true notes: - Requires the redis-py Python package on the remote host. You can install it with pip (C(pip install redis)) or with a package manager. @@ -199,34 +213,24 @@ REDIS_IMP_ERR = traceback.format_exc() HAS_REDIS_PACKAGE = False -from ansible.module_utils.basic import AnsibleModule, missing_required_lib +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.text.converters import to_native - - -def redis_client(**client_params): - return StrictRedis(**client_params) - +from ansible_collections.community.general.plugins.module_utils.redis import ( + fail_imports, redis_auth_argument_spec, redis_auth_params) # Module execution. def main(): module = AnsibleModule( - argument_spec=dict( - login_host=dict(type='str', default='localhost'), - login_port=dict(type='int', default=6379), - login_password=dict(type='str', no_log=True), - ), + argument_spec=redis_auth_argument_spec(tls_default=False), supports_check_mode=True, ) - if not HAS_REDIS_PACKAGE: - module.fail_json(msg=missing_required_lib('redis'), exception=REDIS_IMP_ERR) + fail_imports(module, module.params['tls']) - login_host = module.params['login_host'] - login_port = module.params['login_port'] - login_password = module.params['login_password'] + redis_params = redis_auth_params(module) # Connect and check - client = redis_client(host=login_host, port=login_port, password=login_password) + client = StrictRedis(**redis_params) try: client.ping() except Exception as e: