Giter Club home page Giter Club logo

Comments (23)

gwagroves avatar gwagroves commented on June 6, 2024 27

Ubuntu 16.04. The following worked for me:

vars:
  ansible_python_interpreter: /usr/bin/python3
tasks:
  - name: Install packages
    apt: name={{item}}
    with_items:
      - python3-pip
      - python3-mysqldb

from ansible-role-mysql.

dirkaholic avatar dirkaholic commented on June 6, 2024 21

Just ran into this as well and the solution that works for me on Ubuntu 14.04 as well as on 16.04 is:

- name: Install packages required for ansible mysql modules on Ubuntu before 16.04
  apt: name={{ item }} state=present
  with_items:
    - python-mysqldb
  when: ansible_lsb.major_release|int < 16

- name: Install packages required for ansible mysql modules on Ubuntu 16.04
  apt: name={{ item }} state=present
  with_items:
    - python3-dev
    - libmysqlclient-dev
  when: ansible_lsb.major_release|int >= 16

- name: Install Python package manager on Ubuntu 16.04
  apt: name=python3-pip state=present
  when: ansible_lsb.major_release|int >= 16

- name: Install the Python package required for ansible MySQL modules on Ubuntu 16.04
  pip: name=mysqlclient
  when: ansible_lsb.major_release|int >= 16

from ansible-role-mysql.

andycutright avatar andycutright commented on June 6, 2024 19

For Trusty, running in AWS

- name: install python mysql bindings
  apt: name=python-mysqldb state=installed
  become: yes
  become_method: sudo

from ansible-role-mysql.

timani avatar timani commented on June 6, 2024 9

I was receiving the same error using sudo in my playbook.

You can run sudo pip show MySQL-python to see if the python mysqldb module is loaded for the user.

There were two ways to fix it.

1. Installing python mysqldb module with pip

# Install the python mysqldb module
$ sudo pip install MySQL-python
# Verify python mysqldb module is installed
$ sudo pip show MySQL-python
---
Metadata-Version: 1.1
Name: MySQL-python
Version: 1.2.5
Summary: Python interface to MySQL
Home-page: https://github.com/farcepest/MySQLdb1
Author: Andy Dustman
Author-email: [email protected]
License: GPL
Location: /usr/lib64/python2.7/site-packages
Requires: 

2. Add the mysqldb module in a playbook

It could be easier to install the python module within your playbook

---
# tasks file for mysql
  - name: Install the Python MySQLB module
    pip: name=MySQL-python

  - name: Create the flask database
    mysql_db: name=flask_db state=present

With each fix the playbook ran correctly

$ ansible-playbook ansible/site.yml -c local --ask-sudo-pass

PLAY [localhost] ************************************************************** 

TASK: [common | Database volume container] ************************************ 
ok: [localhost]

TASK: [mysql | Install the Python MySQLB module] ****************************** 
ok: [localhost]

TASK: [mysql | Create the Drupal database] ************************************ 
ok: [localhost]

PLAY RECAP ******************************************************************** 
localhost                  : ok=3    changed=1    unreachable=0    failed=0   

from ansible-role-mysql.

jbarotin avatar jbarotin commented on June 6, 2024 8

This simple code fix the issue (with ubuntu and python3)

- name: Install python MySQL module
  apt:
    name: python3-mysqldb

from ansible-role-mysql.

jhogendorn avatar jhogendorn commented on June 6, 2024 7

For those like me whom end up here via the almighty google, if you're on Centos or anything Centos-like (Amazon Linux for example), the reason MySQL-python is failing for you is because its been made into two packages, MySQL-python26 and MySQL-python27.

from ansible-role-mysql.

geerlingguy avatar geerlingguy commented on June 6, 2024 6

Ugh, Amazon Linux again... why do they have to do everything ever so slightly different than RHEL/CentOS?

Going to close this as there's a definite solution now—make sure the proper MySQL python package is installed before this role is run.

from ansible-role-mysql.

kmoll avatar kmoll commented on June 6, 2024 4

I ran into this using DrupalVM playbook directly to another server running a plain vanilla version of ubunut-16.04 (not Jeffs box). This uses python3 instead of python2 (2.7). You can allow most of the playbook to run by using 'ansible_python_interpreter=/usr/bin/python3' in the inventory file in examples/prod. I get this error still. I try to manually install python_mysqldb but it says its installed and the latest version. Not sure why the mysql_db command in ansible can't find the right package. Seems like this is a bug with Ansible and Python3, not DrupalVM.

I got around it by creating a task to make sure python2 was installed and there was a symlink created:

      apt:
        name: python2.7
        state: present
        update_cache: yes

    - name: create python symlink
      file:
        src: /usr/bin/python2.7
        dest: /usr/bin/python
        owner: root
        group: root
        state: link

According to the docs, at http://docs.drupalvm.com/en/latest/other/production. You run the init.yml file in the production example folder first. This is where I put this task, and in the command line I add the ansible_python_interpreter command:

ansible-playbook -i examples/prod/inventory examples/prod/bootstrap/init.yml -e 'ansible_python_interpreter=/usr/bin/python3'

This will then run and make sure python2 is install, then you can run the command without specifying the interpreter with the playbook.yml file and it will work:

ansible-playbook -i examples/prod/inventory provisioning/playbook.yml --sudo --ask-sudo-pass

from ansible-role-mysql.

gsirvas avatar gsirvas commented on June 6, 2024 4

I was having this issue on an Amazon Linux instance:
I installed the following packages and I no longer get that error.

  - name: Install OS packages
    yum: name={{item}} state=present
    with_items:
      - mysql-devel
      - gcc
      - python-devel
      - MySQL-python

  - name: Install MySQL-Python  module
    pip: name=MySQL-python

from ansible-role-mysql.

ryancastle avatar ryancastle commented on June 6, 2024 3

@gwagroves answer works well, but just the module is sufficient.

- name: Install the MySQL-python module
  apt: name=python3-mysqldb state=present

from ansible-role-mysql.

pio2pio avatar pio2pio commented on June 6, 2024 3

On Ubuntu 18.04 LTS , with Ansible 1.9.4 and Python 2.7.15+, I've Installed:

sudo apt install python-mysqldb

from ansible-role-mysql.

cstavaru avatar cstavaru commented on June 6, 2024 1

Actually, this is not fixed and it's a real issue on Amazon Linux. Installing MySQL-python with pip will fail because a file (my_config.h) which is actually installed by the geerlingguy.mysql role, will be missing. Package python-devel must also be installed beforehand.

I think the true solution is supporting Amazon Linux as a first-class citizen (with its own configuration and list of packages to install).

But, this is easier said than done. As far as I can see, the ansible_os_family variable returns "RedHat" for Amazon Linux because it returns "RedHat" for CentOS. So changes are needed to better distinguish Amazon Linux.

from ansible-role-mysql.

mglaman avatar mglaman commented on June 6, 2024 1

Ran into this on DigitalOcean, all of my droplets are 16.04

Inventory file

[forkdin:vars]
ansible_ssh_user=XXXXXXX
deploy_target=XXXXXXX
ansible_python_interpreter=/usr/bin/python3

Database playbook

---
- hosts: database
  become: yes

  vars_files:
    - vars.yml

  pre_tasks:
    - name: Ensure dependencies are installed.
      apt: name={{ item }} state=present
      with_items:
        - python3-mysqldb

  roles:
    - { role: geerlingguy.firewall, tags: ['firewall'] }
    - { role: geerlingguy.mysql, tags: ['mysql'] }

  tags:
    - database

from ansible-role-mysql.

maxolasersquad avatar maxolasersquad commented on June 6, 2024 1

Lots of solutions here, some rather complicated, but @jbarotin answer is the only one needed, which simply installs the one missing package needed to get things working.

from ansible-role-mysql.

ryancastle avatar ryancastle commented on June 6, 2024 1

Remote host requires it.

from ansible-role-mysql.

ngstigator avatar ngstigator commented on June 6, 2024 1

Using Ubuntu 18.04, pre-installing the python3-mysqldb module does not work for me as I still get the requirement error. I need to install the python2 version of the module (python-mysqldb) for the role to run smoothly. I've tried installing the python3 module both as a pre-task, and in a role that is run before the mysql role. python3 is also the default interpreter, set in ansible.cfg as well as in a script using update-alternatives.

from ansible-role-mysql.

geerlingguy avatar geerlingguy commented on June 6, 2024

I haven't seen this issue on any of the servers I manage, so I wonder if it's something unique about the Amazon Linux AMIs/setup... Can you make sure the sudo user is able to import mySQLdb as well? Maybe it's only installed in a Python environment accessible to your normal user.

from ansible-role-mysql.

kmoll avatar kmoll commented on June 6, 2024

I checked the box geerlingguy/ubuntu1604 and this already had python2.7 along side python3.5 so I didn't run into the issue there.

from ansible-role-mysql.

mindcurv-jerald avatar mindcurv-jerald commented on June 6, 2024

Any solution or Centos or Redhat ?
I get the same error:

TASK [Mysql_Base : Mysql - Change root pasword for TEST]
fatal: [vmTEST01]: FAILED! => {"changed": false, "failed": true, "msg": "The MySQL-python module is required."}
fatal: [vmTEST02]: FAILED! => {"changed": false, "failed": true, "msg": "The MySQL-python module is required."}

from ansible-role-mysql.

MariusHerget avatar MariusHerget commented on June 6, 2024

I have the same issue and none of the previous solutions works. I need to run a MariaDB on Debian GNU/Linux 9 (64-bit). Manually installing the lib via pip install mysql-python runs into some errors since I do not use the standard MySQL packages.

from ansible-role-mysql.

victorbiga avatar victorbiga commented on June 6, 2024

perhaps book should be updated to include the below on page 30

$ ansible db -b -m yum -a "name=MySQL-python27 state=present"

from ansible-role-mysql.

ranjeetranjan avatar ranjeetranjan commented on June 6, 2024

I am facing below issue when I try to create user from my local-machine to remote-host.

TASK [mysqluser : mysql_user] *******************************************************************************************************************
fatal: [remote-host]: FAILED! => {"changed": false, "failed": true, "msg": "the python mysqldb module is required"}
	to retry, use: --limit @/Users/adsizzler/server-setup/mysql.retry

Do I need to install the mysqldb module on local machine or remote-host?

from ansible-role-mysql.

podarok avatar podarok commented on June 6, 2024

Python2 Ubuntu 20

sudo wget https://raw.githubusercontent.com/paulfitz/mysql-connector-c/master/include/my_config.h -O /usr/include/mysql/my_config.h
pip install --index=https://pypi.python.org/pypi/ MySQL-python

from ansible-role-mysql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.