From 2de30ed7cb547efbcb3b67f6826af6900cdef459 Mon Sep 17 00:00:00 2001
From: Andrew Klychkov <aklychko@redhat.com>
Date: Sat, 2 Apr 2022 18:33:46 +0300
Subject: [PATCH] [stable-2] Backports (#324)

* Clarified error message about missing python modules (#279)

* Clarified error message about missing python modules, and tweak documentation to suggest overriding interpreter.

* Mention mysqlclient as another option

* Correct mysqlclient suggestions from python2 to python3

Co-authored-by: Matthew Exon <git.mexon@spamgourmet.com>
(cherry picked from commit 82baf7508ce757b102e229b51f902c46cf18bebc)

* Copy ignore-2.13.txt to ignore-2.14.txt (#323)

* Copy ignore-2.13.txt to ignore-2.14.txt

* Fix sanity

(cherry picked from commit c16b2428e80f8f837469d41fca48f6b0015fab8f)

Co-authored-by: Matthew Exon <github2.mexon@neverbox.com>
---
 plugins/doc_fragments/mysql.py | 11 +++++++----
 plugins/module_utils/mysql.py  |  5 ++++-
 tests/sanity/ignore-2.14.txt   |  8 ++++++++
 3 files changed, 19 insertions(+), 5 deletions(-)
 create mode 100644 tests/sanity/ignore-2.14.txt

diff --git a/plugins/doc_fragments/mysql.py b/plugins/doc_fragments/mysql.py
index 9cc5bce..4b531d4 100644
--- a/plugins/doc_fragments/mysql.py
+++ b/plugins/doc_fragments/mysql.py
@@ -79,10 +79,13 @@ notes:
      The Python package may be installed with apt-get install python-pymysql (Ubuntu; see M(ansible.builtin.apt)) or
      yum install python2-PyMySQL (RHEL/CentOS/Fedora; see M(ansible.builtin.yum)). You can also use dnf install python2-PyMySQL
      for newer versions of Fedora; see M(ansible.builtin.dnf).
-   - Be sure you have PyMySQL or MySQLdb library installed on the target machine
-     for the Python interpreter Ansible uses, for example, if it is Python 3,
-     you must install the library for Python 3. You can also change the interpreter.
-     For more information, see U(https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html).
+   - Be sure you have mysqlclient, PyMySQL, or MySQLdb library installed on the target machine
+     for the Python interpreter Ansible discovers.  For example if ansible discovers and uses Python 3, you need to install
+     the Python 3 version of PyMySQL or mysqlclient.  If ansible discovers and uses Python 2, you need to install the Python 2
+     version of either PyMySQL or MySQL-python.
+   - If you have trouble, it may help to force Ansible to use the Python interpreter you need by specifying
+     C(ansible_python_interpreter).  For more information, see
+     U(https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html).
    - Both C(login_password) and C(login_user) are required when you are
      passing credentials. If none are present, the module will attempt to read
      the credentials from C(~/.my.cnf), and finally fall back to using the MySQL
diff --git a/plugins/module_utils/mysql.py b/plugins/module_utils/mysql.py
index 5af9c20..9492ea8 100644
--- a/plugins/module_utils/mysql.py
+++ b/plugins/module_utils/mysql.py
@@ -29,7 +29,10 @@ except ImportError:
     except ImportError:
         mysql_driver = None
 
-mysql_driver_fail_msg = 'The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required.'
+mysql_driver_fail_msg = ('A MySQL module is required: for Python 2.7 either PyMySQL, or '
+                         'MySQL-python, or for Python 3.X mysqlclient or PyMySQL. '
+                         'Consider setting ansible_python_interpreter to use '
+                         'the intended Python version.')
 
 
 def parse_from_mysql_config_file(cnf):
diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt
new file mode 100644
index 0000000..c0323af
--- /dev/null
+++ b/tests/sanity/ignore-2.14.txt
@@ -0,0 +1,8 @@
+plugins/modules/mysql_db.py validate-modules:doc-elements-mismatch
+plugins/modules/mysql_db.py validate-modules:parameter-list-no-elements
+plugins/modules/mysql_db.py validate-modules:use-run-command-not-popen
+plugins/modules/mysql_info.py validate-modules:doc-elements-mismatch
+plugins/modules/mysql_info.py validate-modules:parameter-list-no-elements
+plugins/modules/mysql_query.py validate-modules:parameter-list-no-elements
+plugins/modules/mysql_user.py validate-modules:undocumented-parameter
+plugins/modules/mysql_variables.py validate-modules:doc-required-mismatch