puppet - How can I improve class function using a template or other generic method -


i have class function downloads packages using package method in puppet.

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

i use in init.pp so

# install dependencies $dependence_list = ['glibc.i686','wget','gcc'] # # ==actions # install glibc, gcc, wget dependency running sybase #  # ==requires # * http proxy setup around jpm proxy package::install { $dependence_list:       dependence => file[ $http_setup_name ],       } 

i method more generic. possible instead of using array of dependencies, need edit init.pp each time. use template , read each dependency file? or other generic method do...

an example great.

you should able set requirement within package , pass array package too:

 $my_packages = ['apache2', 'curl', 'wget']  $my_dependencies = [file['a'], file['b'], user['tester']]   package { $my_packages:    ensure  => installed,    require => $my_dependencies,  } 

using type of package should sufficient needs.

however if want read dependency list file can use 'template' function. ie.

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

finally you're dependency_list.erb this:

[file['a'], file['b'], user['tester']] 

and that's there it!

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


Comments