#!/usr/bin/ruby -w #-------------------- # Print out a puppet config that matches our object type require 'getoptlong' require 'puppet' #[ "--size", "-s", GetoptLong::REQUIRED_ARGUMENT ], result = GetoptLong.new( [ "--edit", "-e", GetoptLong::NO_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ] ) edit = false result.each { |opt,arg| case opt when "--edit" edit = true when "--help" puts "There is no help yet" exit else raise "Invalid option '#{opt}'" end } type = nil if ARGV.length > 0 type = ARGV.shift else raise "You must specify the type to display" end typeobj = nil unless typeobj = Puppet::Type.type(type) raise "Could not find type %s" % type end states = typeobj.states.collect { |s| s.name } text = typeobj.list.collect do |obj| next if ARGV.length > 0 and ! ARGV.include? obj.name trans = obj.to_trans trans.dup.each do |param, value| if value == "" or value == [] trans.delete(param) end unless states.include?(param) trans.delete(param) end end trans.to_manifest end.reject { |t| t.nil? }.join("\n") if edit file = "/tmp/x2puppet-#{$$}.pp" begin File.open(file, "w") do |f| f.puts text end system(ENV["EDITOR"], file) system("puppet -v " + file) ensure #if FileTest.exists? file # File.unlink(file) #end end else puts text end