From 5d9469831bf0c364c5ef3cfc5877dd408d8ff68b Mon Sep 17 00:00:00 2001 From: Jorge-Rodriguez Date: Sun, 4 Oct 2020 10:37:38 +0300 Subject: [PATCH] Ignore `check_hostname` when using MySQLdb --- plugins/doc_fragments/mysql.py | 3 ++- plugins/module_utils/mysql.py | 2 -- tests/integration/targets/test_mysql_db/tasks/issue-28.yml | 7 ++++++- .../integration/targets/test_mysql_info/tasks/issue-28.yml | 7 ++++++- .../targets/test_mysql_query/tasks/issue-28.yml | 7 ++++++- .../targets/test_mysql_replication/tasks/issue-28.yml | 7 ++++++- .../integration/targets/test_mysql_user/tasks/issue-28.yml | 7 ++++++- .../targets/test_mysql_variables/tasks/issue-28.yml | 7 ++++++- 8 files changed, 38 insertions(+), 9 deletions(-) diff --git a/plugins/doc_fragments/mysql.py b/plugins/doc_fragments/mysql.py index 4f5f2fd..3032073 100644 --- a/plugins/doc_fragments/mysql.py +++ b/plugins/doc_fragments/mysql.py @@ -66,7 +66,8 @@ options: description: - Whether to validate the server host name when an SSL connection is required. - Setting this to False disables hostname verification. Use with caution. - - Requires pymysql >= 0.7.11. MySQLdb does not support this option. + - Requires pymysql >= 0.7.11. + - This optoin has no effect on MySQLdb. type: bool requirements: - PyMySQL (Python 2.7 and Python 3.X), or diff --git a/plugins/module_utils/mysql.py b/plugins/module_utils/mysql.py index fa5b92d..3c3fda9 100644 --- a/plugins/module_utils/mysql.py +++ b/plugins/module_utils/mysql.py @@ -87,8 +87,6 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='', config['ssl']['check_hostname'] = check_hostname else: module.fail_json(msg='To use check_hostname, pymysql >= 0.7.11 is required on the target host') - else: - module.fail_json(msg='Connector %s does not support the check_hostname option' % mysql_driver.__name__) if _mysql_cursor_param == 'cursor': # In case of PyMySQL driver: diff --git a/tests/integration/targets/test_mysql_db/tasks/issue-28.yml b/tests/integration/targets/test_mysql_db/tasks/issue-28.yml index fbf5dfd..871e92d 100644 --- a/tests/integration/targets/test_mysql_db/tasks/issue-28.yml +++ b/tests/integration/targets/test_mysql_db/tasks/issue-28.yml @@ -51,6 +51,11 @@ - result is failed when: pymysql_version.stdout != "" + - assert: + that: + - result is succeeded + when: pymysql_version.stdout == "" + - name: attempt connection with newly created user ignoring hostname mysql_db: name: '{{ db_name }}' @@ -66,7 +71,7 @@ - assert: that: - - result is succeeded or 'pymysql >= 0.7.11 is required' in result.msg or 'MySQLdb does not support' in result.msg + - result is succeeded or 'pymysql >= 0.7.11 is required' in result.msg - name: Drop mysql user mysql_user: diff --git a/tests/integration/targets/test_mysql_info/tasks/issue-28.yml b/tests/integration/targets/test_mysql_info/tasks/issue-28.yml index ceb9f4a..955683d 100644 --- a/tests/integration/targets/test_mysql_info/tasks/issue-28.yml +++ b/tests/integration/targets/test_mysql_info/tasks/issue-28.yml @@ -49,6 +49,11 @@ - result is failed when: pymysql_version.stdout != "" + - assert: + that: + - result is succeeded + when: pymysql_version.stdout == "" + - name: attempt connection with newly created user ignoring hostname mysql_info: filter: version @@ -63,7 +68,7 @@ - assert: that: - - result is succeeded or 'pymysql >= 0.7.11 is required' in result.msg or 'MySQLdb does not support' in result.msg + - result is succeeded or 'pymysql >= 0.7.11 is required' in result.msg - name: Drop mysql user mysql_user: diff --git a/tests/integration/targets/test_mysql_query/tasks/issue-28.yml b/tests/integration/targets/test_mysql_query/tasks/issue-28.yml index 05c19a0..e2b51a6 100644 --- a/tests/integration/targets/test_mysql_query/tasks/issue-28.yml +++ b/tests/integration/targets/test_mysql_query/tasks/issue-28.yml @@ -49,6 +49,11 @@ - result is failed when: pymysql_version.stdout != "" + - assert: + that: + - result is succeeded + when: pymysql_version.stdout == "" + - name: attempt connection with newly created user ignoring hostname mysql_query: query: 'SHOW DATABASES' @@ -63,7 +68,7 @@ - assert: that: - - result is succeeded or 'pymysql >= 0.7.11 is required' in result.msg or 'MySQLdb does not support' in result.msg + - result is succeeded or 'pymysql >= 0.7.11 is required' in result.msg - name: Drop mysql user mysql_user: diff --git a/tests/integration/targets/test_mysql_replication/tasks/issue-28.yml b/tests/integration/targets/test_mysql_replication/tasks/issue-28.yml index 4e098de..c666820 100644 --- a/tests/integration/targets/test_mysql_replication/tasks/issue-28.yml +++ b/tests/integration/targets/test_mysql_replication/tasks/issue-28.yml @@ -50,6 +50,11 @@ - result is failed when: pymysql_version.stdout != "" + - assert: + that: + - result is succeeded + when: pymysql_version.stdout == "" + - name: attempt connection with newly created user ignoring hostname mysql_replication: mode: getmaster @@ -64,7 +69,7 @@ - assert: that: - - result is succeeded or 'pymysql >= 0.7.11 is required' in result.msg or 'MySQLdb does not support' in result.msg + - result is succeeded or 'pymysql >= 0.7.11 is required' in result.msg - name: Drop mysql user mysql_user: diff --git a/tests/integration/targets/test_mysql_user/tasks/issue-28.yml b/tests/integration/targets/test_mysql_user/tasks/issue-28.yml index fda5988..a5b3d2a 100644 --- a/tests/integration/targets/test_mysql_user/tasks/issue-28.yml +++ b/tests/integration/targets/test_mysql_user/tasks/issue-28.yml @@ -52,6 +52,11 @@ - result is failed when: pymysql_version.stdout != "" + - assert: + that: + - result is succeeded + when: pymysql_version.stdout == "" + - name: attempt connection with newly created user ignoring hostname mysql_user: name: "{{ user_name_2 }}" @@ -68,7 +73,7 @@ - assert: that: - - result is succeeded or 'pymysql >= 0.7.11 is required' in result.msg or 'MySQLdb does not support' in result.msg + - result is succeeded or 'pymysql >= 0.7.11 is required' in result.msg - name: Drop mysql user mysql_user: diff --git a/tests/integration/targets/test_mysql_variables/tasks/issue-28.yml b/tests/integration/targets/test_mysql_variables/tasks/issue-28.yml index 720abce..056771e 100644 --- a/tests/integration/targets/test_mysql_variables/tasks/issue-28.yml +++ b/tests/integration/targets/test_mysql_variables/tasks/issue-28.yml @@ -50,6 +50,11 @@ - result is failed when: pymysql_version.stdout != "" + - assert: + that: + - result is succeeded + when: pymysql_version.stdout == "" + - name: attempt connection with newly created user ignoring hostname mysql_variables: variable: '{{ set_name }}' @@ -64,7 +69,7 @@ - assert: that: - - result is succeeded or 'pymysql >= 0.7.11 is required' in result.msg or 'MySQLdb does not support' in result.msg + - result is succeeded or 'pymysql >= 0.7.11 is required' in result.msg - name: Drop mysql user mysql_user: