2019-03-17 14:10:04 +00:00
|
|
|
---
|
2023-06-29 13:17:06 +00:00
|
|
|
- name: Create the data directory
|
2021-08-22 14:09:18 +00:00
|
|
|
ansible.builtin.file:
|
2019-03-17 14:10:04 +00:00
|
|
|
path: '{{ mariadb_full_config.mysqld.datadir }}'
|
|
|
|
owner: '{{ mariadb_full_config.mysqld.user }}'
|
|
|
|
group: root
|
|
|
|
mode: 0750
|
|
|
|
state: directory
|
|
|
|
tags: mariadb
|
|
|
|
|
2023-06-29 13:17:06 +00:00
|
|
|
- name: Initialize database # noqa no-changed-when
|
2021-08-22 14:09:18 +00:00
|
|
|
ansible.builtin.command:
|
2019-03-17 14:10:04 +00:00
|
|
|
args:
|
|
|
|
argv:
|
|
|
|
- mysql_install_db
|
|
|
|
- '--datadir={{ mariadb_full_config.mysqld.datadir }}'
|
|
|
|
- '--user={{ mariadb_full_config.mysqld.user }}'
|
|
|
|
- '--skip-name-resolve'
|
|
|
|
- '--no-defaults'
|
|
|
|
tags: mariadb
|
|
|
|
|
2023-06-29 13:17:06 +00:00
|
|
|
- name: Start mariadb
|
2021-08-22 14:09:18 +00:00
|
|
|
ansible.builtin.service:
|
2019-03-17 14:10:04 +00:00
|
|
|
name: mysql
|
|
|
|
state: started
|
|
|
|
tags: mariadb
|
|
|
|
|
2023-06-29 13:17:06 +00:00
|
|
|
- name: Wait mysql start
|
2021-08-22 14:09:18 +00:00
|
|
|
ansible.builtin.pause:
|
2019-03-17 14:10:04 +00:00
|
|
|
seconds: 5
|
|
|
|
tags: mariadb
|
|
|
|
|
2023-06-29 13:17:06 +00:00
|
|
|
- name: Set root password # noqa no-changed-when
|
2021-08-22 14:09:18 +00:00
|
|
|
ansible.builtin.command: 'mysqladmin -u root password {{ mariadb_password }}'
|
2019-03-17 14:10:04 +00:00
|
|
|
tags: mariadb
|
2019-03-17 15:03:37 +00:00
|
|
|
|
2023-06-29 13:17:06 +00:00
|
|
|
- name: Remove anonymous users
|
2021-08-22 14:09:18 +00:00
|
|
|
community.mysql.mysql_user:
|
2019-03-17 15:03:37 +00:00
|
|
|
name: ''
|
|
|
|
host_all: yes
|
|
|
|
state: absent
|
|
|
|
login_user: '{{ mariadb_user }}'
|
|
|
|
login_password: '{{ mariadb_password }}'
|
|
|
|
tags: mariadb
|
|
|
|
|
2023-06-29 13:17:06 +00:00
|
|
|
- name: Remove root user without password
|
2021-08-22 14:09:18 +00:00
|
|
|
community.mysql.mysql_user:
|
2019-03-17 15:03:37 +00:00
|
|
|
name: root
|
|
|
|
host: '{{ item }}'
|
|
|
|
state: absent
|
|
|
|
login_user: '{{ mariadb_user }}'
|
|
|
|
login_password: '{{ mariadb_password }}'
|
|
|
|
loop:
|
|
|
|
- 127.0.0.1
|
|
|
|
- '::1'
|
|
|
|
- '{{ ansible_nodename }}'
|
|
|
|
tags: mariadb
|