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

36 lines
1 KiB
YAML
Raw Normal View History

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:33:10 +01:00
name: mariadb-server
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"
notify: Start mysqld service
- name: Secure the installation
become: true
block:
- name: Set root password
mysql_user: user=root password="" host=localhost
no_log: true
- 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 }}
no_log: true
with_items:
- "::1"
- "127.0.0.1"
- localhost
- name: Remove test database
mysql_db: db=test state=absent
when: "'table already exists!' not in result.stdout"