diff --git a/README.md b/README.md index bbcce21..6b6a716 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ Whether MySQL should be enabled on startup. 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. + 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. + mysql_databases: [] 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. @@ -75,13 +79,6 @@ Slow query log settings. Note that the log file will be created by this role, bu The rest of the settings in `defaults/main.yml` control MySQL's memory usage. The default values are tuned for a server where MySQL can consume ~512 MB RAM, so you should consider adjusting them to suit your particular server better. - mysqld_performance_settings: - - { name: key_buffer_size, value: "256M" } - mysql_dump_settings: [] - - { name: mysqldump_max_allowed_packet, value: "64M" } - -Any additional performance settings you would like to add beyond the defaults. - mysql_server_id: "1" mysql_max_binlog_size: "100M" mysql_expire_logs_days: "10" diff --git a/defaults/main.yml b/defaults/main.yml index 8c886fe..69bb143 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -28,8 +28,6 @@ mysql_bind_address: '0.0.0.0' mysql_datadir: /var/lib/mysql mysql_pid_file: /var/run/mysqld/mysqld.pid -mysqld_performance_settings: [] - # Slow query log settings. mysql_slow_query_log_enabled: no mysql_slow_query_log_file: /var/log/mysql-slow.log @@ -67,13 +65,18 @@ mysql_innodb_lock_wait_timeout: 50 # mysqldump settings. mysql_mysqldump_max_allowed_packet: "64M" -mysql_dump_settings: [] - # Logging settings. mysql_log: "" mysql_log_error: /var/log/mysql.err mysql_syslog_tag: mysql +mysql_config_include_files: [] +# Full example: +# mysql_config_include_files: +# - src: path/relative/to/playbook/file.cnf +# - { src: path/relative/to/playbook/anotherfile.cnf, force: yes } + + # Databases. mysql_databases: [] # Full example: diff --git a/tasks/configure.yml b/tasks/configure.yml index a913f3a..c0ccd5b 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -9,6 +9,26 @@ force: "{{ overwrite_global_mycnf }}" notify: restart mysql +- name: Verify mysql include directory exists. + file: + path: "{{ mysql_config_include_dir }}" + state: directory + owner: root + group: root + mode: 0755 + when: mysql_config_include_files|length + +- name: Copy my.cnf override files into include directory. + 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 + notify: restart mysql + - name: Create slow query log file (if configured). shell: "touch {{ mysql_slow_query_log_file }} creates={{ mysql_slow_query_log_file }}" when: mysql_slow_query_log_enabled diff --git a/templates/my.cnf.j2 b/templates/my.cnf.j2 index 26f4c92..c16c5ab 100644 --- a/templates/my.cnf.j2 +++ b/templates/my.cnf.j2 @@ -90,16 +90,16 @@ innodb_log_buffer_size = {{ mysql_innodb_log_buffer_size }} innodb_flush_log_at_trx_commit = {{ mysql_innodb_flush_log_at_trx_commit }} innodb_lock_wait_timeout = {{ mysql_innodb_lock_wait_timeout }} -{% for setting in mysqld_performance_settings %} -{{ setting.name }} = {{ setting.value }} -{% endfor %} - [mysqldump] quick max_allowed_packet = {{ mysql_mysqldump_max_allowed_packet }} -{% for setting in mysql_dump_settings %} -{{ setting.name }} = {{ setting.value }} -{% endfor %} [mysqld_safe] pid-file = {{ mysql_pid_file }} + +{% if mysql_config_include_files|length %} +# * IMPORTANT: Additional settings that can override those from this file! +# The files must end with '.cnf', otherwise they'll be ignored. +# +!includedir {{ mysql_config_include_dir }} +{% endif %} \ No newline at end of file diff --git a/vars/Debian.yml b/vars/Debian.yml index 55c88e8..4156d55 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -5,4 +5,5 @@ __mysql_packages: - mysql-server __mysql_slow_query_log_file: /var/log/mysql/mysql-slow.log mysql_config_file: /etc/mysql/my.cnf +mysql_config_include_dir: /etc/mysql/conf.d/ mysql_socket: /var/run/mysqld/mysqld.sock diff --git a/vars/RedHat.yml b/vars/RedHat.yml index cc483d1..71117a2 100644 --- a/vars/RedHat.yml +++ b/vars/RedHat.yml @@ -5,4 +5,5 @@ __mysql_packages: - mysql-server __mysql_slow_query_log_file: /var/log/mysql-slow.log mysql_config_file: /etc/my.cnf +mysql_config_include_dir: /etc/my.cnf.d mysql_socket: /var/lib/mysql/mysql.sock