Skip to content

Commit 19f403e

Browse files
committed
Allow mysql_config_include_files to contain raw content
In some cases, specifying a known src path in `mysql_config_include_files` is not possible / complicated and it may be much cleaner to provide raw file content to be sent. In that case, we need to use the `ansible.builtin.copy` module. We can extend the current implementation by simply filtering on whether `src` or `content` is set in each item in `mysql_config_include_files`
1 parent 210caa2 commit 19f403e

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Whether the global my.cnf should be overwritten each time this role is run. Sett
6868
mysql_config_include_files: []
6969
```
7070

71-
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.
71+
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.
7272

7373
```yaml
7474
mysql_databases: []

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ mysql_log: ""
107107
mysql_config_include_files: []
108108
# - src: path/relative/to/playbook/file.cnf
109109
# - { src: path/relative/to/playbook/anotherfile.cnf, force: true }
110+
# - content: |
111+
# # some included configuration here
112+
# dst: yetanotherfile.cnf
110113

111114
# Databases.
112115
mysql_databases: []

tasks/configure.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,30 @@
3131
mode: 0755
3232
when: mysql_config_include_files | length
3333

34-
- name: Copy my.cnf override files into include directory.
34+
- name: Template my.cnf override files into include directory.
3535
ansible.builtin.template:
3636
src: "{{ item.src }}"
3737
dest: "{{ mysql_config_include_dir }}/{{ item.src | basename }}"
3838
owner: root
3939
group: root
4040
mode: 0644
4141
force: "{{ item.force | default(false) }}"
42-
with_items: "{{ mysql_config_include_files }}"
42+
with_items: "{{ mysql_config_include_files | selectattr('src', 'defined') }}"
43+
loop_control:
44+
label: "{{ item.src | basename }}"
45+
notify: restart mysql
46+
47+
- name: Copy my.cnf override files into include directory.
48+
ansible.builtin.copy:
49+
content: "{{ item.content }}"
50+
dest: "{{ mysql_config_include_dir }}/{{ item.dst }}"
51+
owner: root
52+
group: root
53+
mode: 0644
54+
force: "{{ item.force | default(false) }}"
55+
with_items: "{{ mysql_config_include_files | selectattr('content', 'defined') }}"
56+
loop_control:
57+
label: "{{ item.dst }}"
4358
notify: restart mysql
4459

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

0 commit comments

Comments
 (0)