How do I install a Python module on localhost so that Ansible finds it?

I want to use the community.mysql.mysql_user module. It requires PyMySQL or MySQLdb. I installed PyYySQL with pip3 install pymysql on localhost, but an error message about the missing PyMySQL still appeared. I thought perhaps I should install to a system directory with sudo, but the error still appeared.

The following did not help either, after uninstalling with pip3 again:

  • sudo apt install --yes python3-pymysql
  • sudo apt install --yes python3-mysqldb

The installation command from the PyMySQL page on PYPI (python3 -m pip install pymysql) gave this output:

Requirement already satisfied: PyMySQL in /usr/lib/python3/dist-packages (0.9.3)

Localhost is WSL2 Ubuntu 20.04.


Solution 1:

PyMySQL is a requirement on the host that executes the module. The module needs to be installed on the server running the msql server not the computer where ansible-playbook playbook.yml is executed.