上QQ阅读APP看书,第一时间看更新
Hardening a database service
We have seen setting up the database. The following code snippet shows how we can harden the MySQL service by binding it to localhost and the required interfaces for interacting with the application. It then removes the anonymous user and test databases:
- name: delete anonymous mysql user for localhost
mysql_user:
user: ""
state: absent
login_password: "{{ mysql_root_password }}"
login_user: root
- name: secure mysql root user
mysql_user:
user: "root"
password: "{{ mysql_root_password }}"
host: "{{ item }}"
login_password: "{{ mysql_root_password }}"
login_user: root
with_items:
- 127.0.0.1
- localhost
- ::1
- "{{ ansible_fqdn }}"
- name: removes mysql test database
mysql_db:
db: test
state: absent
login_password: "{{ mysql_root_password }}"
login_user: root