这是我的 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