From 9f066c60f3c965ada31be7690ec61e1c493a36ca Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Mon, 22 Jun 2015 16:12:15 -0400 Subject: Add a function to write package names This function writes out package names that have been defined in a given puppet catalog. In order to work this should be place last (or very late) in a manifest to ensure it picks up packages. Change-Id: Ie21b5bf7df71337da02ea43915dc4e70d3052bb7 --- lib/puppet/parser/functions/write_package_names.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/puppet/parser/functions/write_package_names.rb (limited to 'lib') diff --git a/lib/puppet/parser/functions/write_package_names.rb b/lib/puppet/parser/functions/write_package_names.rb new file mode 100644 index 0000000..8f99674 --- /dev/null +++ b/lib/puppet/parser/functions/write_package_names.rb @@ -0,0 +1,22 @@ +require 'fileutils' + +module Puppet::Parser::Functions + newfunction(:write_package_names, :doc => "Write package names which are managed via this puppet run to a file.") do |arg| + if arg[0].class == String + begin + output_file = arg[0] + packages = catalog.resources.collect { |r| r.title if r.type == 'Package' }.compact + FileUtils.mkdir_p(File.dirname(output_file)) + File.open(output_file, 'w') do |f| + packages.each do |pkg_name| + f.write(pkg_name + "\n") + end + end + rescue JSON::ParserError + raise Puppet::ParseError, "Syntax error: #{arg[0]} is invalid" + end + else + raise Puppet::ParseError, "Syntax error: #{arg[0]} is not a String" + end + end +end -- cgit 1.2.3-korg