automating mysql my.cnf with puppet

100 views
Skip to first unread message

Tim Dunphy

unread,
Sep 15, 2015, 3:59:56 PM9/15/15
to puppet...@googlegroups.com
Hey guys,

 Is there any other way to automate this setting in my.cnf:

server-id=1

So that if the host is db1 it'll get a value of 1, for db2 a value of 2, for db3 a value of 3 and db4 a value of 4?

The only way I can think of this is to have branching logic in the puppet manifest that does a test on the $hostname fact. But then you'd have to have 4 files corresponding to each host. 

But I'd like to find a way to get this to happen automatically using templates. 

I'm already setting up the SSL certs for the DB servers using the fqdn fact like this:

ssl-cert=/opt/mysql/<%= fqdn %>.crt
ssl-key=/opt/mysql/<%= fqdn %>.key


I'm looking for a way to just have one my.cnf template for all 4 db hosts that automatically assigns the right value to server-id the way I describe above. 

Any suggestions that could allow for that would be very welcome!

Thanks,
Tim

--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B

Christopher

unread,
Sep 15, 2015, 4:06:44 PM9/15/15
to puppet...@googlegroups.com
Try something like this to extract the \d from the hostname:
<% id = fqdn.dup %>
<% id.gsub!(/db(\d).domain.ext/){$1} %>
server-id = <%= id %>
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAOZy0ekzV%2B8PAHjHVMiVmWS6%3DvXo2FNLpGowtWu-%2B-qCFKe6Tg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Christopher Wood

unread,
Sep 15, 2015, 4:07:42 PM9/15/15
to puppet...@googlegroups.com
Use a regular expression? Untested:

server-id=<%= @hostname.match(/db([0-9]+)/); $1 %>
> gpg --keyserver [1]pool.sks-keyservers.net --recv-keys F186197B
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [2]puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> [3]https://groups.google.com/d/msgid/puppet-users/CAOZy0ekzV%2B8PAHjHVMiVmWS6%3DvXo2FNLpGowtWu-%2B-qCFKe6Tg%40mail.gmail.com.
> For more options, visit [4]https://groups.google.com/d/optout.
>
> References
>
> Visible links
> 1. http://pool.sks-keyservers.net/
> 2. mailto:puppet-users...@googlegroups.com
> 3. https://groups.google.com/d/msgid/puppet-users/CAOZy0ekzV%2B8PAHjHVMiVmWS6%3DvXo2FNLpGowtWu-%2B-qCFKe6Tg%40mail.gmail.com?utm_medium=email&utm_source=footer
> 4. https://groups.google.com/d/optout

Ramin K

unread,
Sep 15, 2015, 4:15:27 PM9/15/15
to puppet...@googlegroups.com
On 9/15/15 12:59 PM, Tim Dunphy wrote:
> Hey guys,
>
> Is there any other way to automate this setting in my.cnf:
>
> server-id=1
>
> So that if the host is db1 it'll get a value of 1, for db2 a value of 2,
> for db3 a value of 3 and db4 a value of 4?

Don't bother. Assigning the number manually and incrementally while
satisfying to our collective sense of order providers no value whatsoever.

What I would recommend is making it a unique 32 bit number which is all
the is necessary via one of these methods.

server_id = <% require 'ipaddr'%><%= IPAddr.new(@ipaddress).to_i %>
server_id = fqdn_rand(2147483647).

Ramin

Ramin K

unread,
Sep 15, 2015, 4:18:41 PM9/15/15
to puppet...@googlegroups.com
On 9/15/15 1:15 PM, Ramin K wrote:

> server_id = <% require 'ipaddr'%><%= IPAddr.new(@ipaddress).to_i %>
> server_id = fqdn_rand(2147483647).

that last should have been <%= scope.function_fqdn_rand(2147483647) %>
assuming it was also in a template.

Ramin

Tim Dunphy

unread,
Sep 19, 2015, 10:19:14 PM9/19/15
to puppet...@googlegroups.com
Hey all,

 Ok, sorry if I didn't get to all of your suggestions. But I did elect to try this one: 

server-id=<%= @hostname.match(/db([0-9]+)/); $1 %>

Which I modified slightly to:

server-id=<%= @hostname.match(/db([0-4]+)/); $1 %>

Because I only run 4 mysql servers atm.

And BOOM! That does it exactly right!!

On db1 I get:

server-id=1

on db2:

server-id=2

and so on and so on. Works perfectly. Shout out to Christopher Wood for his "untested" regex expression. Which when tested worked perfectly!

Thanks,
Tim



Ramin

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/55F87CFB.5020103%40badapple.net.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages