ansible-role-mariadb/tasks/main.yml

69 lines
1.5 KiB
YAML

---
- import_tasks: repo.yml
when: mariadb_use_official_repository|bool
- name: install package
package:
name: '{{ packages }}'
vars:
packages:
- mariadb-server
- python-mysqldb
- python3-mysqldb
retries: 2
register: result
until: result is succeeded
tags: mariadb
- name: copy configuration file
template:
src: my.cnf.j2
dest: /etc/mysql/my.cnf
owner: root
group: root
mode: 0644
notify: restart mariadb
tags: mariadb
- name: check if datadir exist
stat:
path: '{{ mariadb_full_config.mysqld.datadir }}'
register: st
tags: mariadb
- import_tasks: initdb.yml
when: not st.stat.exists
- name: enable and start the service
service:
name: mysql
state: started
enabled: yes
tags: mariadb
- name: manage users
mysql_user:
name: '{{ item.name }}'
host: '{{ item.host }}'
password: '{{ item.password }}'
priv: '{{ item.privileges|default("")|join(",") }}'
state: '{{ item.state|default("present") }}'
login_user: '{{ mariadb_user }}'
login_password: '{{ mariadb_password }}'
loop: '{{ mariadb_users }}'
run_once: true
no_log: true
when: mariadb_master|bool
tags: mariadb
- name: manage databases
mysql_db:
name: '{{ item.name }}'
state: '{{ item.state|default("present") }}'
login_user: '{{ mariadb_user }}'
login_password: '{{ mariadb_password }}'
loop: '{{ mariadb_databases }}'
run_once: true
no_log: true
when: mariadb_master|bool
tags: mariadb