mysql/database: Added database_template function

dehydrated
Felix Stupp 5 years ago
parent c6309b92ad
commit 424b85eec8
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -3,3 +3,5 @@
# database_user
database_pass: "{{ lookup('password', 'credentials/' + inventory_hostname + '/mysql/' + database_user + ' length=80') }}"
database_name: "{{ database_user }}"
# database_template # Template (content, not path) for database if just created

@ -0,0 +1,24 @@
---
- name: Generate temporary filename
tempfile:
state: file
suffix: .sql
register: sql_temp
- name: Copy SQL template to remote
copy:
content: "{{ database_template }}"
dest: "{{ sql_temp.path }}"
- name: Import SQL database template on creation
mysql_db:
state: import
name: "{{ database_name }}"
target: "{{ sql_temp.path }}"
login_unix_socket: "/var/run/mysqld/mysqld.sock"
- name: Remove SQL template from remote
file:
state: absent
path: "{{ sql_temp.path }}"

@ -16,3 +16,8 @@
mysql_db:
db: "{{ database_name }}"
login_unix_socket: "/var/run/mysqld/mysqld.sock"
register: create_database
- name: Import SQL database template on creation
include_tasks: import.yml
when: create_database.changed and database_template is defined

Loading…
Cancel
Save