问题原文
原帖链接 · Prince Joseph · CC BY-SA 4.0
I managed to install Apache Mysql/Mariadb and PHP using playbook. How can I do mysql_secure_installation using ansible?
I am a beginner in Ansible. I want to set a new password to MySQL server and complete all security questions via playbook.
社区高分解答
原帖链接 · Michael Hampton · CC BY-SA 4.0
I implemented this myself for my MariaDB installations some time back, and before I trusted anyone else to do it correctly. These are the steps I performed:
# mysql_secure_installation
- name: Update MariaDB root password
mysql_user: name=root host={{item}} password={{mysql_root_password}}
with_items:
- 127.0.0.1
- ::1
- localhost
- name: Set ~/.my.cnf file
template: src=dotmy.cnf.j2 dest=/root/.my.cnf mode=0600
# mysql_secure_installation
- name: Delete anonymous MySQL user
mysql_user: name="" host={{item}} state=absent
with_items:
- localhost
- "{{ansible_nodename}}"
# mysql_secure_installation
- name: Delete Hostname based MySQL user
mysql_user: name=root host="{{ansible_nodename}}" state=absent
# mysql_secure_installation
- name: Remove MySQL test database
mysql_db: name=test state=absent
You'll have to decide how to create mysql_root_password yourself.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
