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
> 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
Works a treat. (as always!)
Thanks for the heads-up.
How do I get this into the puppet/facter documentation?
Matt
not sure where would be appropriate, I just got that from the facter code - looked what it does for --puppet :)
--
R.I.Pienaar
Doh!
M.