我想在AWS上安装一个MySQL服务器,使用Ansible进行配置管理.
当执行下面的 playbook 时,一切都很顺利.但是当我第二次运行它时,task Configure the root credentials
失败了,因为MySQL的旧密码不再匹配,因为它在我上次运行这个 playbook 时已经更新了.
这使得 playbook 不是幂等的,我不喜欢.我希望能够尽可能多地运行 playbook .
- hosts: staging_mysql
user: ec2-user
sudo: yes
tasks:
- name: Install MySQL
action: yum name=$item
with_items:
- MySQL-python
- mysql
- mysql-server
- name: Start the MySQL service
action: service name=mysqld state=started
- name: Configure the root credentials
action: command mysqladmin -u root -p $mysql_root_password
解决这个问题的最好方法是什么,也就是说让 playbook 幂等?提前谢谢!