ansible-role-mariadb/tasks/initdb.yml

61 lines
1.4 KiB
YAML

---
- name: create the data directory
ansible.builtin.file:
path: '{{ mariadb_full_config.mysqld.datadir }}'
owner: '{{ mariadb_full_config.mysqld.user }}'
group: root
mode: 0750
state: directory
tags: mariadb
- name: initialize database
ansible.builtin.command:
args:
argv:
- mysql_install_db
- '--datadir={{ mariadb_full_config.mysqld.datadir }}'
- '--user={{ mariadb_full_config.mysqld.user }}'
- '--skip-name-resolve'
- '--no-defaults'
when: True
tags: mariadb
- name: start mariadb
ansible.builtin.service:
name: mysql
state: started
tags: mariadb
- name: wait mysql start
ansible.builtin.pause:
seconds: 5
tags: mariadb
- name: set root password
ansible.builtin.command: 'mysqladmin -u root password {{ mariadb_password }}'
when: True
tags: mariadb
- name: remove anonymous users
community.mysql.mysql_user:
name: ''
host_all: yes
state: absent
login_user: '{{ mariadb_user }}'
login_password: '{{ mariadb_password }}'
no_log: true
tags: mariadb
- name: remove root user without password
community.mysql.mysql_user:
name: root
host: '{{ item }}'
state: absent
login_user: '{{ mariadb_user }}'
login_password: '{{ mariadb_password }}'
loop:
- 127.0.0.1
- '::1'
- '{{ ansible_nodename }}'
no_log: true
tags: mariadb