2022-05-09 20:26:15 +03:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: MySQL | Install packages
|
|
|
|
package:
|
|
|
|
name: "{{ mysql_packages }}"
|
|
|
|
state: present
|
|
|
|
|
|
|
|
- name: MySQL | Deploy main config
|
|
|
|
template:
|
|
|
|
src: "{{ mysql_main_conf.src }}"
|
2022-05-09 21:35:20 +03:00
|
|
|
dest: "{{ mysql_main_conf.dest | d('/etc/my.cnf') }}"
|
2022-05-09 20:26:15 +03:00
|
|
|
mode: "{{ mysql_configs_mode }}"
|
|
|
|
owner: "{{ mysql_configs_user }}"
|
|
|
|
group: "{{ mysql_configs_user }}"
|
|
|
|
when: mysql_main_conf.src is defined
|
|
|
|
notify: MySQL | Restart
|
|
|
|
|
|
|
|
- name: MySQL | Deploy conf.d files
|
2022-05-09 20:53:21 +03:00
|
|
|
template:
|
2022-05-09 20:26:15 +03:00
|
|
|
src: "{{ item.src }}"
|
|
|
|
dest: "{{ item.dest }}"
|
|
|
|
mode: "{{ mysql_configs_mode }}"
|
|
|
|
owner: "{{ mysql_configs_user }}"
|
|
|
|
group: "{{ mysql_configs_user }}"
|
|
|
|
with_items: "{{ mysql_confd }}"
|
|
|
|
notify: MySQL | Restart
|
|
|
|
|
|
|
|
- name: MySQL | Enable and start
|
|
|
|
service:
|
|
|
|
name: "{{ mysql_service_name }}"
|
|
|
|
state: started
|
2022-05-09 20:57:59 +03:00
|
|
|
enabled: yes
|
2022-05-09 20:26:15 +03:00
|
|
|
|
|
|
|
- name: MySQL | Create databases
|
|
|
|
mysql_db:
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
state: "{{ item.state | d(omit) }}"
|
2022-05-09 21:13:23 +03:00
|
|
|
|
|
|
|
login_unix_socket: "{{ mysql_connection.unix_socket | d(omit) }}"
|
|
|
|
login_host: "{{ mysql_connection.host | d(omit) }}"
|
|
|
|
login_port: "{{ mysql_connection.port | d(omit) }}"
|
|
|
|
login_user: "{{ mysql_connection.user | d(omit) }}"
|
|
|
|
login_password: "{{ mysql_connection.password | d(omit) }}"
|
2022-05-09 20:26:15 +03:00
|
|
|
with_items: "{{ mysql_databases }}"
|
|
|
|
|
|
|
|
- name: MySQL | Create users
|
2023-08-27 23:11:20 +03:00
|
|
|
# TODO: Add more fileds from https://docs.ansible.com/ansible/latest/collections/community/mysql/mysql_user_module.html
|
2022-05-09 20:26:15 +03:00
|
|
|
mysql_user:
|
|
|
|
name: "{{ item.name }}"
|
2023-08-27 23:11:20 +03:00
|
|
|
host: "{{ item.host }}"
|
2022-05-09 21:13:23 +03:00
|
|
|
state: "{{ item.state | d(omit) }}"
|
2022-05-09 20:26:15 +03:00
|
|
|
password: "{{ item.password | d(omit) }}"
|
2022-05-09 21:13:23 +03:00
|
|
|
priv: "{{ item.priv | d(omit) }}"
|
|
|
|
|
|
|
|
login_unix_socket: "{{ mysql_connection.unix_socket | d(omit) }}"
|
|
|
|
login_host: "{{ mysql_connection.host | d(omit) }}"
|
|
|
|
login_port: "{{ mysql_connection.port | d(omit) }}"
|
|
|
|
login_user: "{{ mysql_connection.user | d(omit) }}"
|
|
|
|
login_password: "{{ mysql_connection.password | d(omit) }}"
|
2022-05-09 20:26:15 +03:00
|
|
|
with_items: "{{ mysql_users }}"
|
|
|
|
|
|
|
|
- name: unbound | Run handlers
|
|
|
|
meta: flush_handlers
|