請告訴我如何在 debian 9 中安裝模組 mysql_db 。有必要建立資料庫和使用者。 ansible 文件說 mysql_db 模組用於此目的。在同一頁面下方有訊息
Python 套件可以使用 apt-get install python-pymysql 安裝
我按照場外 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 一起。