Skip to content

Commit a3d3bf2

Browse files
committed
Merge pull request geerlingguy#76 from BlackMesh/allow_custom_variables
Allow configuration of variables not currently supported
2 parents 0c1026d + 1b1e11b commit a3d3bf2

File tree

6 files changed

+39
-0
lines changed

6 files changed

+39
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Whether MySQL should be enabled on startup.
3232

3333
Whether the global my.cnf should be overwritten each time this role is run. Setting this to `no` tells Ansible to only create the `my.cnf` file if it doesn't exist. This should be left at its default value (`yes`) if you'd like to use this role's variables to configure MySQL.
3434

35+
mysql_config_include_files: []
36+
37+
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.
38+
3539
mysql_databases: []
3640

3741
The MySQL databases to create. A database has the values `name`, `encoding` (defaults to `utf8`), `collation` (defaults to `utf8_general_ci`) and `replicate` (defaults to `1`, only used if replication is configured). The formats of these are the same as in the `mysql_db` module.

defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ mysql_log: ""
7070
mysql_log_error: /var/log/mysql.err
7171
mysql_syslog_tag: mysql
7272

73+
mysql_config_include_files: []
74+
# - src: path/relative/to/playbook/file.cnf
75+
# - { src: path/relative/to/playbook/anotherfile.cnf, force: yes }
76+
77+
7378
# Databases.
7479
mysql_databases: []
7580
# Full example:

tasks/configure.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@
99
force: "{{ overwrite_global_mycnf }}"
1010
notify: restart mysql
1111

12+
- name: Verify mysql include directory exists.
13+
file:
14+
path: "{{ mysql_config_include_dir }}"
15+
state: directory
16+
owner: root
17+
group: root
18+
mode: 0755
19+
when: mysql_config_include_files | length
20+
21+
- name: Copy my.cnf override files into include directory.
22+
template:
23+
src: "{{ item.src }}"
24+
dest: "{{ mysql_config_include_dir }}/{{ item.src | basename }}"
25+
owner: root
26+
group: root
27+
mode: 0644
28+
force: "{{ item.force | default(False) }}"
29+
with_items: mysql_config_include_files
30+
notify: restart mysql
31+
1232
- name: Create slow query log file (if configured).
1333
shell: "touch {{ mysql_slow_query_log_file }} creates={{ mysql_slow_query_log_file }}"
1434
when: mysql_slow_query_log_enabled

templates/my.cnf.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,11 @@ max_allowed_packet = {{ mysql_mysqldump_max_allowed_packet }}
9696

9797
[mysqld_safe]
9898
pid-file = {{ mysql_pid_file }}
99+
100+
{% if mysql_config_include_files | length %}
101+
# * IMPORTANT: Additional settings that can override those from this file!
102+
# The files must end with '.cnf', otherwise they'll be ignored.
103+
#
104+
!includedir {{ mysql_config_include_dir }}
105+
{% endif %}
106+

vars/Debian.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ __mysql_packages:
55
- mysql-server
66
__mysql_slow_query_log_file: /var/log/mysql/mysql-slow.log
77
mysql_config_file: /etc/mysql/my.cnf
8+
mysql_config_include_dir: /etc/mysql/conf.d
89
mysql_socket: /var/run/mysqld/mysqld.sock

vars/RedHat.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ __mysql_packages:
55
- mysql-server
66
__mysql_slow_query_log_file: /var/log/mysql-slow.log
77
mysql_config_file: /etc/my.cnf
8+
mysql_config_include_dir: /etc/my.cnf.d
89
mysql_socket: /var/lib/mysql/mysql.sock

0 commit comments

Comments
 (0)