Using FACTER in other ruby code

2,799 views
Skip to first unread message

Matthew Macdonald-Wallace

unread,
Sep 2, 2010, 8:49:10 AM9/2/10
to puppet-users
Hi all,

I'm trying to write a ruby script to setup MySQL replication base on
facts that we can distribute at runtime.

I have two facts(mysql_master and mysql_repl_dbs) that show up when I
run facter --puppet, however they do not appear to be imported in the
following script:

=================================

#!/usr/bin/ruby
#
# mysql-replication.rb
#
# This script uses facter to setup mysql replication based upon the
facts mysql_master and mysql_repl_dbs
#
# It is currently in beta
#


# 1) Require the relevant libraries
require 'rubygems'
require 'facter'
require 'mysql'

# 2) Get the relevant facts and echo them to the screen
puts "Getting facts"
begin
Facter.mysql_master
puts "Facts received"
rescue
Facter.loadfacts()
puts "running rescue"
end

mysql_master = Facter.value('mysql_master')
mysql_repl_dbs = Facter.value('mysql_master')

puts "Master Server: #{mysql_master}\nDatabases: #{mysql_repl_dbs}"


==================

The output from the script is as follows:

Getting facts
running rescue
Master Server:
Databases:


where as facter --puppet mysql_master shows the correct hostname.

Am I missing a trick here?

Thanks,

Matt

R.I.Pienaar

unread,
Sep 2, 2010, 8:52:39 AM9/2/10
to puppet...@googlegroups.com

----- "Matthew Macdonald-Wallace" <mattm...@gmail.com> wrote:

> Hi all,
>
> I'm trying to write a ruby script to setup MySQL replication base on
> facts that we can distribute at runtime.
>
> I have two facts(mysql_master and mysql_repl_dbs) that show up when I
> run facter --puppet, however they do not appear to be imported in the
> following script:
>
> =================================
>
> #!/usr/bin/ruby
> #
> # mysql-replication.rb
> #
> # This script uses facter to setup mysql replication based upon the
> facts mysql_master and mysql_repl_dbs
> #
> # It is currently in beta
> #
>
>
> # 1) Require the relevant libraries
> require 'rubygems'
> require 'facter'
> require 'mysql'

add around here:

ENV['FACTERLIB'] = "/var/lib/puppet/lib/facter:/var/lib/puppet/facts"

substitute with wherever your pluginsync is putting the facts

Matthew Macdonald-Wallace

unread,
Sep 2, 2010, 9:09:00 AM9/2/10
to puppet...@googlegroups.com
On 2 September 2010 13:52, R.I.Pienaar <r...@devco.net> wrote:
>
> add around here:
>
> ENV['FACTERLIB'] = "/var/lib/puppet/lib/facter:/var/lib/puppet/facts"
>
> substitute with wherever your pluginsync is putting the facts

Works a treat. (as always!)

Thanks for the heads-up.

How do I get this into the puppet/facter documentation?

Matt

R.I.Pienaar

unread,
Sep 2, 2010, 9:14:16 AM9/2/10
to puppet...@googlegroups.com

----- "Matthew Macdonald-Wallace" <mattm...@gmail.com> wrote:

not sure where would be appropriate, I just got that from the facter code - looked what it does for --puppet :)

--
R.I.Pienaar

Matthew Macdonald-Wallace

unread,
Sep 2, 2010, 9:28:03 AM9/2/10
to puppet...@googlegroups.com
On 2 September 2010 14:14, R.I.Pienaar <r...@devco.net> wrote:
> not sure where would be appropriate, I just got that from the facter code - looked what it does for --puppet :)

Doh!

M.

Charlotte McLaughlin

unread,
May 14, 2013, 2:34:17 PM5/14/13
to puppet...@googlegroups.com
Matt

Did you ever get puppet to automate replication between a master mysql db and a slave mysql db. For example my host for the master is db01.xxx.xxx and the slave is db01.xxx.xxx. This seems to be an issue Puppet Labs does not support. Once I get a working solution I would like to present a presentation to San Francisco Puppet Master's group as a demo to spread the knowledge. Thanks

Mac
Reply all
Reply to author
Forward
0 new messages