![Ansible mysql_* 模块在首次启动时显示错误](https://linux22.com/image/154431/Ansible%20mysql_*%20%E6%A8%A1%E5%9D%97%E5%9C%A8%E9%A6%96%E6%AC%A1%E5%90%AF%E5%8A%A8%E6%97%B6%E6%98%BE%E7%A4%BA%E9%94%99%E8%AF%AF.png)
这是我的 yml 文件,它应该更新系统、安装 mysql-server、更改绑定并运行“mysql_secure_installation”中的步骤。
---
# tasks file for deploy_db
- name: Update repos
apt:
name: "*"
state: latest
update_cache: yes
- name: Install mysql
apt:
name:
- mysql-server
- python-pymysql
- python-apt
state: latest
- name: Autostart mysql
service:
name: mysql
enabled: yes
- name: Change mysql default binding
replace:
path: /etc/mysql/mysql.conf.d/mysqld.cnf
regexp: '127.0.0.1'
replace: '0.0.0.0'
- name: Reboot after initial update
reboot:
- name: Remove the test database
mysql_db:
login_unix_socket: /var/run/mysqld/mysqld.sock
name: test
state: absent
- name: Remove anonymous user
mysql_user:
login_unix_socket: /var/run/mysqld/mysqld.sock
name: ''
state: absent
如果我第一次玩这个 yml - Ansible 会显示错误:
TASK [deploy_db : Remove the test database] ********************************************************************************************************************
fatal: [db]: FAILED! => {"changed": false, "msg": "The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required."}
如果我第二次播放同一个文件 - 一切正常。
我做错了什么?任务“删除测试数据库”所需的“python-pymysql”已在之前的一些步骤中安装,并且重新启动,一切都应该有效,但事实并非如此!
答案1
哦,正确的问题是答案的一半:-)我已经修改了任务,现在一切正常
- name: Install mysql
apt:
name:
- mysql-server
- python-pymysql
- python3-pymysql
- python-apt
- python3-apt
state: latest