ansible-role-mariadb/tasks/main.yml

69 lines
1.4 KiB
YAML
Raw Normal View History

2019-02-21 21:19:56 +00:00
---
2019-05-18 10:26:37 +00:00
- import_tasks: repo.yml
when: mariadb_use_official_repository|bool
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
2019-05-18 10:26:37 +00:00
dest: /etc/mysql/my.cnf
2019-02-21 21:19:56 +00:00
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