phd68lnx
phd68lnx

Reputation: 73

Ansible requires PyMSQL but it's already installed

I looked up the similar questions and applied the fixes there but they don't help. Ive been running in circles all day and figured I'd ask for some help.

Ansible controller is Fedora 34 with ansible 2.9.25. Python 3.9.7 with latest PyMySQL installed.

The controlled node is Red Hat 8.4 with python 3.9.2 and PyMySQL installed as well.

When I try to create a MySQL database, I get the following error message:

TASK [role_create_mysql_db : Create MySQL DB *********************************************
Thursday 16 September 2021  12:26:33 +0200 (0:00:04.633)       0:00:15.916 **** 
fatal: [dbserver.bla.domain.com]: FAILED! => {
    "changed": false
}

MSG:

The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required.

I checked the module is available for both root and the ansible remote user. The ansible code is as follows:

- name: Create MySQL database
  mysql_db:
    name: somedbname
    encoding: utf8
    collation: utf8_bin
  become: true

It can't be more straightforward than this.

I tried running ansible-playbook playbook.yml -e ansible_python_interpreter=/usr/bin/python but also with python3, 3.9 and 3.9.whatever version is installed in /usr/bin/python*

It just doesn't want to see PyMySQL is actually installed.

Any help please?

Thanks in advance!

Upvotes: 0

Views: 574

Answers (1)

Unsel
Unsel

Reputation: 363

I've come across this issue before a while ago and I don't really remember how I solved it. However I can share my code with you, maybe it will solve your problem. For a debian host, I've used this before.

- name: Upgrade pip to be able to install pymysql
  pip:
     name: pip
     extra_args: --upgrade

- name: Install pip PyMySQL package
  pip:
     name: PyMySQL

And for a fresh centos7 host, I've used the code below:

- name: Upgrade all packages
  yum:
    name: "*"
    state: latest

- name: Install epel-release
  yum:
    name: epel-release
    state: present

- name: Install python-pip
  yum:
    name: python-pip
    state: latest

- name: Install pexpect
  pip:
    name: pexpect
    state: latest

I've installed those dependencies to later use for my database and cluster operations using mysql modules. This was for a fresh install so I don't know if installing epel-release will cause you any issues or if it was really related to the PyMySQL issue. But you can try those until you have a direct answer.

Upvotes: 2

Related Questions