Ottomata has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/169722

Change subject: Add defines for working with mysql config files, and mysql 
client settings
......................................................................

Add defines for working with mysql config files, and mysql client settings

Change-Id: I81cf2238346455f229a5cdb79ea93371fdcce2af
---
A modules/mysql/manifests/config/client.pp
A modules/mysql/manifests/config/file.pp
M modules/mysql/templates/my.conf.cnf.erb
3 files changed, 96 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/22/169722/1

diff --git a/modules/mysql/manifests/config/client.pp 
b/modules/mysql/manifests/config/client.pp
new file mode 100644
index 0000000..84c045f
--- /dev/null
+++ b/modules/mysql/manifests/config/client.pp
@@ -0,0 +1,54 @@
+# == Define mysql::config::client
+# Convenience wrapper for mysql::config::file that only set a few [client] 
settings.
+#
+#
+# Usage:
+#   mysql::config::client { 'myuser':
+#       user => 'myser',
+#       pass => 'mypass',
+#   }
+#
+# This will render /etc/mysql/conf.d/myuser-client.cnf with the content:
+#
+#   [client]
+#   user = myuser
+#   password = mypass
+#   #host=
+#   #port=
+#
+# You can also set host and port if you like.
+#
+define mysql::config::client(
+    $user     = false,
+    $pass     = false,
+    $host     = false,
+    $port     = false,
+    $path     = "/etc/mysql/conf.d/${title}.cnf",
+    $owner    = 'root',
+    $group    = 'root',
+    $mode     = '0444',
+    $template = 'mysql/my.conf.cnf.erb',
+    $ensure   = 'present',
+)
+{
+    if !($user or $pass or $host or $port) {
+        fail('mysql::config::client needs at least one of user, pass, host, or 
port to be set.')
+    }
+
+    mysql::config::file { "${title}-client":
+        ensure     => $ensure,
+        settings => {
+            'client' => {
+                'user'     => $user,
+                'password' => $pass,
+                'host'     => $host,
+                'port'     => $port,
+            },
+        },
+        path       => $path,
+        owner      => $owner,
+        group      => $group,
+        mode       => $mode,
+        template   => $template,
+    }
+}
diff --git a/modules/mysql/manifests/config/file.pp 
b/modules/mysql/manifests/config/file.pp
new file mode 100644
index 0000000..98b1ac9
--- /dev/null
+++ b/modules/mysql/manifests/config/file.pp
@@ -0,0 +1,39 @@
+# == Define mysql::config::file
+#
+# == Usage
+#   mysql::config::file { 'myhost':
+#       'settings' => {
+#           'client' => {
+#               'host' => 'myhost.example.org',
+#               'port' => 3307,
+#           },
+#       },
+#   }
+#
+# This will render /etc/mysql/conf.d/myhost.cnf with the content:
+#
+#   [client]
+#   host = myhost.example.org
+#   port = 3307
+#
+# You could then use this file with the mysql CLI by doing:
+#   mysql --defaults-extra-file=/etc/mysql/conf.d/myhost.cnf
+#
+define mysql::config::file(
+    $settings,
+    $path     = "/etc/mysql/conf.d/${title}.cnf",
+    $owner    = 'root',
+    $group    = 'root',
+    $mode     = '0444',
+    $template = 'mysql/my.conf.cnf.erb',
+    $ensure   = 'present',
+)
+{
+    file { $path:
+        ensure  => $ensure,
+        owner   => $owner,
+        group   => $group,
+        mode    => $mode,
+        content => template($template),
+    }
+}
diff --git a/modules/mysql/templates/my.conf.cnf.erb 
b/modules/mysql/templates/my.conf.cnf.erb
index ad58af3..4fb6264 100644
--- a/modules/mysql/templates/my.conf.cnf.erb
+++ b/modules/mysql/templates/my.conf.cnf.erb
@@ -1,5 +1,6 @@
-### MANAGED BY PUPPET ###
-<% settings.sort.each do |section, content|      -%>
+# Note:  This file is managed by Puppet.
+
+<% @settings.sort.each do |section, config|      -%>
 [<%= section %>]
 <%   content.sort.each do |key, values|          -%>
 <%     [values].flatten.sort.each do |value|     -%>

-- 
To view, visit https://gerrit.wikimedia.org/r/169722
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I81cf2238346455f229a5cdb79ea93371fdcce2af
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ottomata <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to