ansible-role-mariadb/tasks/main.yml

66 lines
1.4 KiB
YAML
Raw Normal View History

2019-02-21 21:19:56 +00:00
---
- name: install package
package:
2019-02-23 19:07:16 +00:00
name: '{{ packages }}'
vars:
packages:
- mariadb-server
- python-mysqldb
2019-02-21 21:19:56 +00:00
retries: 2
register: result
until: result is succeeded
tags: mariadb
- name: copy configuration file
template:
src: my.cnf.j2
dest: /etc/mysql/mariadb.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
2019-02-21 21:19:56 +00:00
- 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
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
tags: mariadb