From fc6458e9e438a76220af57edaef54ccf3228f6f7 Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Thu, 5 Dec 2013 16:19:52 -0500 Subject: manage configuration snippets in a conf.d directory this should make it easier to override values from my.cnf, or to set other values that aren't in the main config file. --- manifests/conf.pp | 36 ++++++++++++++++++++++++++++++++++++ manifests/server/base.pp | 8 ++++++++ templates/conf.erb | 9 +++++++++ 3 files changed, 53 insertions(+) create mode 100644 manifests/conf.pp create mode 100644 templates/conf.erb diff --git a/manifests/conf.pp b/manifests/conf.pp new file mode 100644 index 0000000..069c012 --- /dev/null +++ b/manifests/conf.pp @@ -0,0 +1,36 @@ +# $config needs to be a hash of key => value pairs. +# +# values in config are output as key = value, except when the value is empty; +# then just key is output. if you need to output an empty value in the form +# key = value, then you can specify empty quotes as the value (see example). +# +# mysql::conf { 'test': +# ensure => present, +# section => 'mysqld', +# config => { +# table_cache => '15000', +# skip_slave => '', +# something => '""', +# } +# } +# +# This will generate the following contents: +# [mysqld] +# skip_slave +# something = "" +# table_cache = 15000 +# +define mysql::conf ( + $section, + $config, + $ensure = present +) { + + include mysql::server::base + + file { "/etc/mysql/conf.d/${name}.cnf": + ensure => $ensure, + content => template('mysql/conf.erb'), + } + +} diff --git a/manifests/server/base.pp b/manifests/server/base.pp index 14f3c1b..4a29591 100644 --- a/manifests/server/base.pp +++ b/manifests/server/base.pp @@ -88,4 +88,12 @@ class mysql::server::base { Mysql_user<<| tag == "mysql_${::fqdn}" |>> Mysql_grant<<| tag == "mysql_${::fqdn}" |>> } + + file { '/etc/mysql/conf.d': + ensure => directory, + owner => 'root', + group => 0, + mode => '0755', + } + } diff --git a/templates/conf.erb b/templates/conf.erb new file mode 100644 index 0000000..c7e332a --- /dev/null +++ b/templates/conf.erb @@ -0,0 +1,9 @@ +# THIS FILE IS MANAGED BY PUPPET +[<%= @section -%>] +<% @config.each do |key, value| -%> +<% if value != '' -%> +<%= key -%> = <%= value %> +<% else -%> +<%= key %> +<% end -%> +<% end %> -- cgit v1.2.3 From e3b382edeb455a7b5c54dbe96f21518a3d49b3d8 Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Wed, 18 Dec 2013 15:15:37 -0500 Subject: conf: notify mysql service to make changes effective --- manifests/conf.pp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/manifests/conf.pp b/manifests/conf.pp index 069c012..f9cbeb3 100644 --- a/manifests/conf.pp +++ b/manifests/conf.pp @@ -29,8 +29,9 @@ define mysql::conf ( include mysql::server::base file { "/etc/mysql/conf.d/${name}.cnf": - ensure => $ensure, - content => template('mysql/conf.erb'), + ensure => $ensure, + content => template('mysql/conf.erb'), + notify => Service['mysql'], } } -- cgit v1.2.3 From b06570a940a705988360553446daa8ea52e60f27 Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Wed, 12 Mar 2014 16:25:58 -0400 Subject: Document the new define in the README Signed-off-by: Gabriel Filion --- README | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README b/README index a454dbd..b92dd23 100644 --- a/README +++ b/README @@ -46,6 +46,36 @@ grant tables. The my.cnf file will installed from one of many possible places, see manifests/server/base.pp for possible locations for managing this. +Configuration snippets +---------------------- + +To make managing mysql configuration easier, you can use the define +mysql::conf. Note, though that there currently is only the Debian default +configuration file that includes files in /etc/mysql/conf.d/. + +For example: + +mysql::conf { 'test': + ensure => present, + section => 'mysqld', + config => { + table_cache => '15000', + skip_slave => '', + something => '""', + } +} + +The above example shows two possibilities for empty values. + + * If a value only has an empty value in the hash passed to the config + parameter, that will define a boolean option in mysql by simply mentioning + the option name with no equal sign. So in the above, you'd have a line that + contains only "skip_slave". + + * If you need to declare a variable with an empty value (e.g. with the equal + sign), you can use two quotes as the option's value. In the above example, + you'd have a line that looks like "something=". + Backups ------- -- cgit v1.2.3