Joe McDonagh
2009-Sep-28 15:00 UTC
[Puppet Users] Capistrano roles filled in using puppet''s stored config db
Hello puppeteers, if anyone is interested I have figured how to fill in
capistrano roles via the stored config db. I have the following script
served out to my puppetmasters via puppet (gethosts.rb):
#!/usr/bin/env ruby
require "puppet"
ActiveRecord::Base.establish_connection(
:adapter => ''mysql'',
:database => ''puppet'',
:host => ''localhost'',
:password => ''puppet'',
:username => ''puppet''
)
class Hosts < Puppet::Rails::Host; end
puts Hosts.find(:all,
:include => [ :fact_values, :fact_names ],
:conditions => [ "fact_names.name = ?
and fact_values.value = ?",
"operatingsystem",
"ubuntu"
]
).map { |host| host.name }
This lists, line by line, my ubuntu boxes. In a Capfile I have:
role :puppet_masters,
"puppet.whatever.com"
role :ubuntu do end
task :enum, :roles => [:puppet_masters] do
desc "Enumerate hosts from puppet DB"
hosts = Hash.new
logger.info "Hosts:"
run ''/usr/local/bin/gethosts.rb'', :pty => true do |ch,
stream, out|
next if out.chomp == ''''
logger.info out.sub(/\//,'' '')
out.split("\r\n").each do |host|
role(:ubuntu, host)
end
end
end
enum
Later on I can do something like
task :aptup_all, :roles => [ :ubuntu ]
run "sudo apt-get update -y && sudo apt-get upgrade -y"
end
Of course this is pretty rudimentary, but I plan on extending my Capfile
to do a lot more tasks.
--
Joe McDonagh
Operations Engineer
www.colonfail.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---