Skip to content

Instantly share code, notes, and snippets.

@bernd
Created February 25, 2013 07:00
Show Gist options
  • Save bernd/5028220 to your computer and use it in GitHub Desktop.
Save bernd/5028220 to your computer and use it in GitHub Desktop.
Playing with puppet for fpm-cookery
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