Skip to content

Commit 49e7642

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 9f580ee commit 49e7642

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
@@ -104,6 +104,9 @@ mysql_log: ""
104104
mysql_config_include_files: []
105105
# - src: path/relative/to/playbook/file.cnf
106106
# - { src: path/relative/to/playbook/anotherfile.cnf, force: yes }
107+
# - content: |
108+
# # some included configuration here
109+
# dst: yetanotherfile.cnf
107110

108111
# Databases.
109112
mysql_databases: []

tasks/configure.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,30 @@
2424
mode: 0755
2525
when: mysql_config_include_files | length
2626

27-
- name: Copy my.cnf override files into include directory.
27+
- name: Template my.cnf override files into include directory.
2828
ansible.builtin.template:
2929
src: "{{ item.src }}"
3030
dest: "{{ mysql_config_include_dir }}/{{ item.src | basename }}"
3131
owner: root
3232
group: root
3333
mode: 0644
3434
force: "{{ item.force | default(False) }}"
35-
with_items: "{{ mysql_config_include_files }}"
35+
with_items: "{{ mysql_config_include_files | selectattr('src', 'defined') }}"
36+
loop_control:
37+
label: "{{ item.src | basename }}"
38+
notify: restart mysql
39+
40+
- name: Copy my.cnf override files into include directory.
41+
ansible.builtin.copy:
42+
content: "{{ item.content }}"
43+
dest: "{{ mysql_config_include_dir }}/{{ item.dst }}"
44+
owner: root
45+
group: root
46+
mode: 0644
47+
force: "{{ item.force | default(False) }}"
48+
with_items: "{{ mysql_config_include_files | selectattr('content', 'defined') }}"
49+
loop_control:
50+
label: "{{ item.dst }}"
3651
notify: restart mysql
3752

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

0 commit comments

Comments
 (0)