Created
February 25, 2013 07:00
-
-
Save bernd/5028220 to your computer and use it in GitHub Desktop.
Playing with puppet for fpm-cookery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'puppet' | |
require 'puppet/application' | |
require 'puppet/configurer' | |
Puppet::Util::Log.newdesttype :fpm do | |
def initialize(i) | |
$stderr.sync = true | |
$stdout.sync = true | |
rescue => e | |
puts e.message | |
end | |
def handle(msg) | |
message = {} | |
[:time, :remote, :file, :line, :source, :level, :message].each do |m| | |
if value = msg.send(m) | |
message[m] = value | |
end | |
end | |
puts message.inspect | |
end | |
end | |
class DependencyInstaller < Puppet::Application | |
attr_accessor :packages | |
def main | |
# Puppet::Util::Log.newdestination(:fpm) | |
Puppet::Util::Log.newdestination(:console) | |
Puppet::Util::Log.level = :debug | |
catalog = Puppet::Resource::Catalog.new | |
resparam = {:parameters => {:ensure => :installed}} | |
Array(packages).each do |package| | |
catalog.add_resource(Puppet::Resource.new(:package, package, resparam)) | |
end | |
catalog = catalog.to_ral | |
catalog.finalize | |
# Run the catalog | |
configurer = Puppet::Configurer.new | |
configurer.run(:catalog => catalog, :pluginsync => false) | |
end | |
end | |
installer = DependencyInstaller.new | |
installer.packages = %w(wget) | |
installer.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment