56 lines
1.4 KiB
YAML
56 lines
1.4 KiB
YAML
- name: Install packages.
|
|
tags: mysql
|
|
ansible.builtin.package:
|
|
name:
|
|
- mariadb-server
|
|
- mariadb-client
|
|
- python3-pymysql
|
|
|
|
- name: Remove unnecessary root accounts.
|
|
community.mysql.mysql_user:
|
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
|
name: root
|
|
host: "{{ item }}"
|
|
state: absent
|
|
with_items:
|
|
- 127.0.0.1
|
|
- ::1
|
|
- "{{ ansible_hostname }}"
|
|
|
|
- name: Remove unnecessary anonymous accounts.
|
|
community.mysql.mysql_user:
|
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
|
name: ""
|
|
host: "{{ item }}"
|
|
state: absent
|
|
with_items:
|
|
- 127.0.0.1
|
|
- ::1
|
|
- "{{ ansible_hostname }}"
|
|
|
|
- name: Remove test database.
|
|
community.mysql.mysql_db:
|
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
|
db: tests
|
|
state: absent
|
|
|
|
- name: Create databases.
|
|
community.mysql.mysql_db:
|
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
|
encoding: "{{ item.encoding | default('utf8') }}"
|
|
target: "{{ item.target | default(omit) }}"
|
|
name: "{{ item.name }}"
|
|
state: present
|
|
with_items: "{{ mysql_databases }}"
|
|
|
|
- name: Create database users.
|
|
tags: mysql
|
|
community.mysql.mysql_user:
|
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
|
name: "{{ item.name }}"
|
|
host: "{{ item.host }}"
|
|
password: "{{ item.password }}"
|
|
state: present
|
|
priv: "{{ item.priv }}"
|
|
with_items: "{{ mysql_users }}"
|