82 lines
1.9 KiB
YAML
82 lines
1.9 KiB
YAML
---
|
|
- name: verify if mariadb is installed
|
|
stat:
|
|
path: /usr/bin/mysqld_safe
|
|
register: mariadb_installed
|
|
|
|
- name: install mariadb
|
|
yum:
|
|
name:
|
|
- mariadb-server
|
|
- python3-PyMySQL
|
|
- mariadb-backup
|
|
# - python3-mysql
|
|
- perl-Digest-MD5
|
|
state: installed
|
|
|
|
- name: create directories
|
|
file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
owner: mysql
|
|
group: mysql
|
|
with_items:
|
|
- /var/lib/mysql/data
|
|
- /var/lib/mysql/backup
|
|
- /var/lib/mysql/innodb
|
|
- /var/lib/mysql/logs
|
|
|
|
- name: copy mariadb config file
|
|
copy:
|
|
src: mariadb/my.cnf
|
|
dest: /etc/my.cnf
|
|
|
|
- name: copy mariadb config file
|
|
copy:
|
|
src: "mariadb/{{ item }}"
|
|
dest: "/etc/my.cnf.d/{{ item }}"
|
|
with_items:
|
|
- server.cnf
|
|
- client.cnf
|
|
- mysql-clients.cnf
|
|
|
|
- name: start and enable the mariadb service
|
|
systemd_service:
|
|
state: started
|
|
name: mariadb
|
|
enabled: true
|
|
|
|
- name: set root passowrd
|
|
shell: >
|
|
mysql -u root
|
|
-e "ALTER USER 'root'@'{{ item }}' IDENTIFIED BY '{{ myslql_root_passd }}';"
|
|
with_items:
|
|
# - 127.0.0.1
|
|
- localhost
|
|
when: not mariadb_installed.stat.exists
|
|
|
|
- name: copy .my.cnf
|
|
template:
|
|
src: mariadb/client-my.cnf.j2
|
|
dest: /root/.my.cnf
|
|
|
|
- name: removes all anonymous user accounts
|
|
mysql_user:
|
|
name: ''
|
|
host_all: yes
|
|
state: absent
|
|
when: not mariadb_installed.stat.exists
|
|
|
|
- name: remove the test database
|
|
mysql_db:
|
|
state: absent
|
|
name: test
|
|
register: rmtestdb
|
|
when: not mariadb_installed.stat.exists
|
|
|
|
- name: delete object test from mysql.db
|
|
#shell: mysql -u root --password={{ mariadb_root_db_pass }} -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
|
|
shell: mysql -u root -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
|
|
when: rmtestdb.changed
|
|
|