blob: db69d809dd6291d247c179edf0dab0d6b1cbd970 [file] [log] [blame]
---
# mariadb tasks/main.yml
#
# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
# SPDX-License-Identifier: Apache-2.0
- name: include OS-specific vars
include_vars: "{{ ansible_os_family }}.yml"
- name: include OS-specific tasks
include_tasks: "{{ ansible_os_family }}.yml"
- name: Enable MariaDB Service
service:
name: "{{ mariadb_service }}"
enabled: true
notify:
- start-mariadb
- name: Flush handlers to start MariaDB
meta: flush_handlers
# Secure the installation
- name: Set root user password
mysql_user:
name: root
password: "{{ mariadb_root_password }}"
host_all: true
login_unix_socket: /var/run/mysqld/mysqld.sock
no_log: true
- name: Create root ~/.my.cnf file to specify new password
template:
src: user.my.cnf.j2
dest: "{{ ansible_env.HOME }}/.my.cnf"
owner: root
group: root
mode: 0600
- name: Remove all anonymous users
mysql_user:
name: ''
host_all: true
state: absent
no_log: true
- name: Remove default test database
mysql_db:
name: test
state: absent
# Create databases
- name: Create databases
mysql_db:
name: "{{ item.name }}"
with_items: "{{ mariadb_databases }}"
# Create users
- name: Create users
mysql_user:
name: "{{ item.name }}"
password: "{{ item.password }}"
host: localhost
priv: "{{ item.priv }}"
no_log: true
with_items: "{{ mariadb_users }}"