X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fensure_packages.rb;h=f255c036ef4d08127beb490fd1a45c0b867acd46;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=1bf8bf18b5018f765cacaf2055425929f1aa7e99;hpb=6963202b4b62c2816655ac9532521b018fdf83bd;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb index 1bf8bf18b..f255c036e 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb @@ -1,20 +1,21 @@ # # ensure_packages.rb # - module Puppet::Parser::Functions - newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS -Takes a list of packages and only installs them if they don't already exist. -It optionally takes a hash as a second parameter that will be passed as the -third argument to the ensure_resource() function. - EOS - ) do |arguments| - - if arguments.size > 2 or arguments.size == 0 - raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments given (#{arguments.size} for 1 or 2)") - elsif arguments.size == 2 and !arguments[1].is_a?(Hash) - raise(Puppet::ParseError, 'ensure_packages(): Requires second argument to be a Hash') - end + newfunction(:ensure_packages, :type => :statement, :doc => <<-DOC + @summary + Takes a list of packages and only installs them if they don't already exist. + + It optionally takes a hash as a second parameter that will be passed as the + third argument to the ensure_resource() function. + + @return + install the passed packages + DOC + ) do |arguments| + + raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments given (#{arguments.size} for 1 or 2)") if arguments.size > 2 || arguments.empty? + raise(Puppet::ParseError, 'ensure_packages(): Requires second argument to be a Hash') if arguments.size == 2 && !arguments[1].is_a?(Hash) if arguments[0].is_a?(Hash) if arguments[1] @@ -27,7 +28,7 @@ third argument to the ensure_resource() function. end Puppet::Parser::Functions.function(:ensure_resources) - function_ensure_resources(['package', arguments[0].dup, defaults ]) + function_ensure_resources(['package', arguments[0].dup, defaults]) else packages = Array(arguments[0]) @@ -41,12 +42,10 @@ third argument to the ensure_resource() function. end Puppet::Parser::Functions.function(:ensure_resource) - packages.each { |package_name| - raise(Puppet::ParseError, 'ensure_packages(): Empty String provided for package name') if package_name.length == 0 - if !findresource("Package[#{package_name}]") - function_ensure_resource(['package', package_name, defaults ]) + packages.each do |package_name| + raise(Puppet::ParseError, 'ensure_packages(): Empty String provided for package name') if package_name.empty? + function_ensure_resource(['package', package_name, defaults]) end - } end end end