ansible-role-mysql/tasks/manage_my_db.yml

44 lines
1.3 KiB
YAML

---
- name: manage_my_db | Add databases to mysql, if any
community.mysql.mysql_db:
name: "{{ item.name }}"
collation: "{{ item.collation }}"
encoding: "{{ item.encoding }}"
state: present
login_unix_socket: "{{ mysql_socket }}"
no_log: true
with_items: '{{ mysql_db_data | default([]) }}'
when: item.name is defined
tags: ['mysql', 'mysql_db']
- name: manage_my_db | Add a user for the databases
community.mysql.mysql_user:
name: "{{ item.0.user }}"
password: "{{ item.0.pwd }}"
host: "{{ item.1 }}"
priv: "{{ item.0.name }}.*:{{ item.0.user_grant }}"
state: present
login_unix_socket: "{{ mysql_socket }}"
no_log: true
with_subelements:
- '{{ mysql_db_data | default([]) }}'
- allowed_hosts
when: item.0.name is defined
tags: ['mysql', 'mysql_db', 'mysql_user']
- name: manage_my_db | Additional user privileges, if defined
community.mysql.mysql_user:
name: "{{ item.0.user }}"
append_privs: true
priv: "{{ item.0.name }}.*:{{ item.0.additional_privs }}"
state: present
login_unix_socket: "{{ mysql_socket }}"
no_log: true
with_subelements:
- '{{ mysql_db_data | default([]) }}'
- allowed_hosts
when:
- item.0.name is defined
- item.0.additional_privs is defined
tags: ['mysql', 'mysql_db', 'mysql_user']