self-hosting/roles/setup-mariadb/tasks/main.yml

53 lines
1.4 KiB
YAML

---
- name: Install mariadb
become: true
apt:
name:
- mariadb-server
- python3-pymysql
state: present
update_cache: yes
notify: Start mariadb service
- 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"
notify: Start mariadb service
- name: Secure the installation
become: true
block:
- name: Set root password
mysql_user:
user: root
password: ""
host: localhost
login_unix_socket: /var/run/mysqld/mysqld.sock
- name: Remove anonymous user for ansible_fqdn
mysql_user:
user: ""
host: "{{ ansible_fqdn }}"
state: absent
login_unix_socket: /var/run/mysqld/mysqld.sock
- name: Remove anonymous user for localhost
mysql_user:
user: ""
state: absent
login_unix_socket: /var/run/mysqld/mysqld.sock
- name: Remove remote root access
mysql_user:
user: root
password: ""
host: "{{ item }}"
login_unix_socket: /var/run/mysqld/mysqld.sock
with_items:
- "::1"
- "127.0.0.1"
- localhost
- name: Remove test database
mysql_db:
db: test
state: absent
login_unix_socket: /var/run/mysqld/mysqld.sock