2021-10-31 13:09:44 +01:00
|
|
|
---
|
2022-03-12 17:33:10 +01:00
|
|
|
- name: Install mariadb
|
|
|
|
become: true
|
2021-10-31 13:09:44 +01:00
|
|
|
apt:
|
2022-03-12 17:51:19 +01:00
|
|
|
name:
|
|
|
|
- mariadb-server
|
|
|
|
- python3-pymysql
|
2021-10-31 13:09:44 +01:00
|
|
|
state: present
|
|
|
|
update_cache: yes
|
2022-03-12 17:33:10 +01:00
|
|
|
|
|
|
|
- name: Initialize mariadb
|
|
|
|
become: true
|
|
|
|
command: mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
|
|
|
|
register: result
|
|
|
|
changed_when: "'table already exists!' not in result.stdout"
|
2022-03-12 17:51:19 +01:00
|
|
|
notify: Start mariadb service
|
2022-03-12 17:33:10 +01:00
|
|
|
|
|
|
|
- name: Secure the installation
|
|
|
|
become: true
|
|
|
|
block:
|
|
|
|
- name: Set root password
|
|
|
|
mysql_user: user=root password="" host=localhost
|
|
|
|
- name: Remove anonymous user for ansible_fqdn
|
|
|
|
mysql_user: user="" host={{ ansible_fqdn }} state=absent
|
|
|
|
- name: Remove anonymous user for localhost
|
|
|
|
mysql_user: user="" state=absent
|
|
|
|
- name: Remove remote root access
|
|
|
|
mysql_user: user=root password="" host={{ item }}
|
|
|
|
with_items:
|
|
|
|
- "::1"
|
|
|
|
- "127.0.0.1"
|
|
|
|
- localhost
|
|
|
|
- name: Remove test database
|
|
|
|
mysql_db: db=test state=absent
|