Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error on ansible playbook: the python mysqldb module is required

I'm trying to teach myself ansible by deploying a wordpress instance from a build server to another host server. Both servers are Ubuntu 16.04 and everything works fine until the build gets to running the mysql tasks main.yml file when i get the below error:

"the python mysqldb module is required"

I have included python-mysqldb in my server/tasks/main.yml file so not sure what the error is. Can anyone point me in the right direction please?

mysql/tasks/main.yml

---
# tasks file for mysql
- name: Create mysql database
  mysql_db: name={{ wp_mysql_db }} state=present

- name: Create mysql user
  mysql_user:
    name={{ wp_mysql_user }}
    password={{ wp_mysql_password }}
    priv=*.*:ALL

server/tasks/main.yml

---
# tasks file for server
- name: Update apt cache
  apt: update_cache=yes cache_valid_time=3600
  sudo: yes

- name: Install required software
  apt: name={{ item }} state=present
  sudo: yes
  with_items:
    - apache2
    - python-mysqldb
    - mysql-server
    - mysql-client
    - php7.0
    - php7.0-mysql
    - libapache2-mod-php7.0
    - php7.0-cli
    - php7.0-cgi
    - php7.0-gd
    - php7.0-mcrypt

console output error from running: ansible-playbook playbook.yml -i hosts -u jbloggs -K

TASK [mysql : Create mysql database] *******************************************
task path: /etc/ansible/roles/mysql/tasks/main.yml:3
fatal: [wordpress1]: FAILED! => {"changed": false, "failed": true, "msg": "the python mysqldb module is required"}
like image 753
Phillip Hogan Avatar asked Feb 24 '17 10:02

Phillip Hogan


1 Answers

You can install this as per-req:

- name: Install required software
  apt: name={{ item }} state=present
  sudo: yes
  with_items:
    - apache2
    - build-essential
    - python-dev
    - libmysqlclient-dev
    - python-mysqldb
    - mysql-server
    - mysql-client
    - php7.0
    - php7.0-mysql
    - libapache2-mod-php7.0
    - php7.0-cli
    - php7.0-cgi
    - php7.0-gd
    - php7.0-mcrypt

If that doesn't work then you can do like this:

- name: Install required software
  apt: name={{ item }} state=present
  sudo: yes
  with_items:
    - apache2
    - build-essential
    - python-dev
    - libmysqlclient-dev
    - python-pip
    - mysql-server
    - mysql-client
    - php7.0
    - php7.0-mysql
    - libapache2-mod-php7.0
    - php7.0-cli
    - php7.0-cgi
    - php7.0-gd
    - php7.0-mcrypt

- name: Install the MySQL-python through pip
  sudo: yes
  pip:
    name: "{{ item }}"
    state: forcereinstall
  with_items:
    - pip
    - MySQL-python
like image 112
Arbab Nazar Avatar answered Oct 02 '22 05:10

Arbab Nazar