aboutsummaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions/write_package_names.rb
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-07-10 13:16:44 +0000
committerGerrit Code Review <review@openstack.org>2015-07-10 13:16:44 +0000
commit77662b64a928db04820041fb0fcf764387600f0a (patch)
treec9a9953501d4e49ec2967ef5da0a5dbff0f17b6e /lib/puppet/parser/functions/write_package_names.rb
parent80e25397876dc45a29924060ac67312d18f369f8 (diff)
parent9f066c60f3c965ada31be7690ec61e1c493a36ca (diff)
Merge "Add a function to write package names"
Diffstat (limited to 'lib/puppet/parser/functions/write_package_names.rb')
-rw-r--r--lib/puppet/parser/functions/write_package_names.rb22
1 files changed, 22 insertions, 0 deletions
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