Comments (23)
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.
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.
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.
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.
This simple code fix the issue (with ubuntu and python3)
- name: Install python MySQL module
apt:
name: python3-mysqldb
from ansible-role-mysql.
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.
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.
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.
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.
@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.
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.
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.
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.
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.
Remote host requires it.
from ansible-role-mysql.
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.
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.
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.
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.
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.
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.
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.
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)
- Allow custom MariaDB version using upstream repos HOT 2
- Check master replication status. HOT 3
- Skip replication tasks HOT 8
- Change mysql_bind_address: '0.0.0.0' to mysql_bind_address: '127.0.0.1' in defaults HOT 2
- Add additional innodb tunables to configuration HOT 4
- Missing community.mysql HOT 2
- ERROR! 'include_tasks' is not a valid attribute for a Play HOT 4
- MySQL fails to start when `mysql_datadir` is set to anything other than MySQL's default HOT 13
- Make apt update_cache optional or ignore errors HOT 2
- mysql_extra_config for my.cnf HOT 2
- force mariadb installation on ubuntu 22.04 not working HOT 1
- mysql_bind_address does not override all conf files
- FAILED! => {"changed": false, "msg": "Could not find the requested service mysql: host"} HOT 5
- secure-installation fails on RHEL8 at remove test database. HOT 3
- includedir is set only if mysql_config_include_files is set HOT 2
- error "couldn't resolve module/action 'mysql_user'" when i used in awx HOT 4
- add innodb settings HOT 2
- Warning "Option column_case_sensitive is not provided" during MySQL user setup HOT 2
- 'sudo mysql' allows access w/o password authentication after fresh install HOT 1
- root password with $ or %
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansible-role-mysql.