Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Whether the global my.cnf should be overwritten each time this role is run. Sett
mysql_config_include_files: []
```

A list of files that should override the default global my.cnf. Each item in the array requires a "src" parameter which is a path to a file. An optional "force" parameter can force the file to be updated each time ansible runs.
A list of files that should override the default global my.cnf. Each item in the array requires either a "src" parameter which is a path to a file, or both a "content" (file contents) and a "dst" (file name) parameter. An optional "force" parameter can force the file to be updated each time ansible runs.

```yaml
mysql_databases: []
Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ mysql_log: ""
mysql_config_include_files: []
# - src: path/relative/to/playbook/file.cnf
# - { src: path/relative/to/playbook/anotherfile.cnf, force: true }
# - content: |
# # some included configuration here
# dst: yetanotherfile.cnf

# Databases.
mysql_databases: []
Expand Down
19 changes: 17 additions & 2 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,30 @@
mode: 0755
when: mysql_config_include_files | length

- name: Copy my.cnf override files into include directory.
- name: Template my.cnf override files into include directory.
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ mysql_config_include_dir }}/{{ item.src | basename }}"
owner: root
group: root
mode: 0644
force: "{{ item.force | default(false) }}"
with_items: "{{ mysql_config_include_files }}"
with_items: "{{ mysql_config_include_files | selectattr('src', 'defined') }}"
loop_control:
label: "{{ item.src | basename }}"
notify: restart mysql

- name: Copy my.cnf override files into include directory.
ansible.builtin.copy:
content: "{{ item.content }}"
dest: "{{ mysql_config_include_dir }}/{{ item.dst }}"
owner: root
group: root
mode: 0644
force: "{{ item.force | default(false) }}"
with_items: "{{ mysql_config_include_files | selectattr('content', 'defined') }}"
loop_control:
label: "{{ item.dst }}"
notify: restart mysql

- name: Create slow query log file (if configured).
Expand Down