Skip to content

Instantly share code, notes, and snippets.

@ranguard
Created April 9, 2012 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ranguard/2345549 to your computer and use it in GitHub Desktop.
Save ranguard/2345549 to your computer and use it in GitHub Desktop.
How to use the same list in puppet for multiple locations
$perl_modules = [ 'Data::Pageset', 'perl-module-b' ]
perlbrew::install_modules {
$perl_modules:
perl => 'a-version-of-perl'
}
perlbrew::install_modules {
$perl_modules:
perl => 'a-different-version-of-perl'
}
# or even something like
perlbrew::install_modules {
'some-name-1':
perl => "a-version-of-perl",
toinstall => $perl_modules,
}
perlbrew::install_modules {
'some-name-2':
perl => "a-second-of-perl",
toinstall => $perl_modules,
}
but it's then how to go through the list and merge with the 'perl'
to create a unique identifier which can be passed to a method
along with the module name that I'm not sure on
@pccowboy
Copy link

pccowboy commented Apr 9, 2012

define pkgInstall() {
file { "${title}":
ensure => file,
source => "/modules/perlbrew/files/${title}.tgz",
}

exec{ "${title}":
  command     => 'some/installer ${title}.tgz',
  require     => File["${title}.tgz"],
  refreshonly => true,
}

}
$list1 = PackageList("perl_version_one", 'install')
pkgInstall{ $list1: }

$list2 = PackageList("perl_version_two", 'install')
pkgInstall{ $list2: }

<-- cut here, remainder goes into lib/puppet/parser/functions/PackageList.rb -->

PackageList - generate a list of packages based upon a prefix (or set of prefixes)

This function allows us to manage packages using prefixes set in extlookup. This

method gives us very fine-grained control of packages, without requiring a ton of

"package" declarations.

module Puppet::Parser::Functions
newfunction(:PackageList, :type => :rvalue) do |args|
prefixes = args[0]
infix = args[1]
prefixList = prefixes.split("|")

    packages = Array.new
    datafiles = Array.new
    moduleDir = Puppet.settings.value('confdir').to_s + '/modules/common/provisioner/files/'

    postfixes = Array.new
    postfixes << "all"
    postfixes << lookupvar('operatingsystem').to_s + lookupvar('operatingsystemmajor').to_s


    prefixList.each do |prefix|
      if prefix != "" 
        postfixes.each do |postfix|
          if File.exists?(moduleDir + "#{prefix}_#{infix}_#{postfix}")
              datafiles << moduleDir + "#{prefix}_#{infix}_#{postfix}"
          end
        end
      end
    end

    datafiles.each do |pkglist|
      File.readlines(pkglist).each do |line|
        packages << line.chomp
      end
    end        

    packages.uniq
end

end

vi:tabstop=4:expandtab:ai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment