Question

I have a class function that downloads packages using the package method in puppet.

class package {

  define install( $dependence=File[$dummy_dependence_file])
 {
      package { $name:
            ensure => "installed",
        require => $dependence,
  }
 }
}

I currently use it in my init.pp like so

# install dependencies
$dependence_list = ['glibc.i686','wget','gcc']
#
# ==Actions
# Install glibc, gcc, wget dependency for running sybase
# 
# ==Requires
# * http proxy to be setup to get around jpm proxy
package::install { $dependence_list:
      dependence => File[ $http_setup_name ],
      }

I would like this method to be more generic. Is it possible instead of using a array of dependencies, which I need to edit the init.pp each time. To use a template and read each dependency from a file? Or any other generic method would do...

An example would be great.

Was it helpful?

Solution

you should be able to simply set the requirement within the package and pass an array to the package too:

 $my_packages = ['apache2', 'curl', 'wget']
 $my_dependencies = [File['a'], File['b'], User['tester']]

 package { $my_packages:
   ensure  => installed,
   require => $my_dependencies,
 }

Using this type of package should be sufficient for your needs.

However if you want to read the dependency list from a file you can use the 'template' function. ie.

 $my_dependencies = template('modulepath/templates/dependency_list.erb')

Finally you're dependency_list.erb would look like this:

[File['a'], File['b'], User['tester']]

and that's all there really is to it!

For more information you can see http://docs.puppetlabs.com/guides/templating.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top