self-hosting/roles/setup_mariadb/tasks/main.yml

54 lines
1.5 KiB
YAML
Raw Normal View History

2021-10-31 13:09:44 +01:00
---
2024-04-09 20:21:59 +02:00
2022-03-12 17:33:10 +01:00
- name: Install mariadb
become: true
2022-12-16 20:12:49 +01:00
ansible.builtin.apt:
2022-03-12 17:51:19 +01:00
name:
- mariadb-server
- python3-pymysql
2021-10-31 13:09:44 +01:00
state: present
2022-03-15 13:35:51 +01:00
notify: Start mariadb service
2022-03-12 17:33:10 +01:00
- name: Initialize mariadb
become: true
2022-12-16 20:12:49 +01:00
ansible.builtin.command: "mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql"
2022-03-12 17:33:10 +01:00
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
2022-12-16 20:12:49 +01:00
community.mysql.mysql_user:
2022-03-12 18:29:35 +01:00
user: root
password: ""
host: localhost
login_unix_socket: /var/run/mysqld/mysqld.sock
2024-04-07 11:51:36 +02:00
- name: Remove anonymous user for "{{ ansible_fqdn }}"
2022-12-16 20:12:49 +01:00
community.mysql.mysql_user:
2022-03-12 18:29:35 +01:00
user: ""
host: "{{ ansible_fqdn }}"
state: absent
login_unix_socket: /var/run/mysqld/mysqld.sock
2022-03-12 17:33:10 +01:00
- name: Remove anonymous user for localhost
2022-12-16 20:12:49 +01:00
community.mysql.mysql_user:
2022-03-12 18:29:35 +01:00
user: ""
state: absent
login_unix_socket: /var/run/mysqld/mysqld.sock
2022-03-12 17:33:10 +01:00
- name: Remove remote root access
2022-12-16 20:12:49 +01:00
community.mysql.mysql_user:
2022-03-12 18:29:35 +01:00
user: root
password: ""
host: "{{ item }}"
login_unix_socket: /var/run/mysqld/mysqld.sock
2022-03-12 17:33:10 +01:00
with_items:
- "::1"
- "127.0.0.1"
- localhost
- name: Remove test database
2022-12-16 20:12:49 +01:00
community.mysql.mysql_db:
2022-03-12 18:29:35 +01:00
db: test
state: absent
login_unix_socket: /var/run/mysqld/mysqld.sock