![Ansible 失败:需要 python mysqldb 模块](https://linux22.com/image/1597966/Ansible%20%E5%A4%B1%E8%B4%A5%EF%BC%9A%E9%9C%80%E8%A6%81%20python%20mysqldb%20%E6%A8%A1%E5%9D%97.png)
请告诉我如何在 Debian 9 中安装 mysql_db 模块。我正在用 ansible 编写剧本。需要创建一个数据库和用户。ansible 文档说 mysql_db 模块用于此目的。在同一页的下面有信息
可以使用 apt-get install python-pymysql 安装 Python 包
我根据场外 Ansible 的说明进行安装。
xxxx@instance-3:/etc/ansible$ sudo apt-get install python-pymysql
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
python-pymysql-doc
The following NEW packages will be installed:
python-pymysql
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 61.4 kB of archives.
After this operation, 318 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian stretch/main amd64 python-pymysql all 0.7.10-1 [61.4 kB]
Fetched 61.4 kB in 0s (987 kB/s)
Selecting previously unselected package python-pymysql.
(Reading database ... 55250 files and directories currently installed.)
Preparing to unpack .../python-pymysql_0.7.10-1_all.deb ...
Unpacking python-pymysql (0.7.10-1) ...
Setting up python-pymysql (0.7.10-1) ...
接下来我尝试启动剧本。
xxxx@instance-3:/etc/ansible$ ansible-playbook db.yml
PLAY [create data base] ********************************************************
TASK [setup] *******************************************************************
ok: [xx.xx.xx.xxx]
TASK [db] **********************************************************************
fatal: [xx.xx.xx.xxx]: FAILED! => {"changed": false, "failed": true, "msg": "the python mysqldb module is required"}
[WARNING]: Could not create retry file '/etc/ansible/db.retry'. [Errno 13] Permission denied:
u'/etc/ansible/db.retry'
PLAY RECAP *********************************************************************
xx.xx.xx.xxx : ok=1 changed=0 unreachable=0 failed=1
我的 ansible 剧本
---
- name: create data base
hosts: all
become: yes
tasks:
- name: db
mysql_db:
name: bobdata
state: present
- name: user
mysql_user:
name: wpuser
password: 123456
priv: '*.*:ALL'
state: present
答案1
简短回答
在远程主机上安装 python mysqldb 模块。
细节
失败!=> {...“msg”:“需要 python mysqldb 模块”...
引自要求
执行此模块的主机需要满足以下要求。
- MySQLdb(Python 2.x)
- PyMySQL(Python 2.7 和 Python 3.X),或
- mysql(命令行二进制)
- mysqldump(命令行二进制)
“ The host that executes this module
“ 是个远程主机。
例如在 FreeBSD 中(作为远程主机)
$ pkg info | grep -i MySQLdb
py27-MySQLdb-1.2.5_1 Access a MySQL database through Python
FWIW,有一个未解决的问题需要 MySQL-python 模块 #906使用 Debian。