On Wednesday, February 26, 2014 3:56:52 AM UTC-6, Richard Fussenegger wrote: > > Right now my init.pp contains the following code block: > > package { [ 'package-1', 'package-2', '...' ]: > ensure => 'present', > require => *Exec*['apt_update'], > } > > This works great — no problem there — but I'd love to use a single init.ppfor > production and development and control the behavior of everything via > my Hiera files. This would also allow me to exchange some packages > depending on the operating system without writing modules for simple > package installations. I tried a few things and searched for answers; > without luck. > > Maybe you guys have an idea on how to solve this. > >
There is a variety of ways to work the details, but most boil down to this basic paradigm: data: my_module::packages: - 'package-1' - 'package-2' ... class: class my_module { $packages = hiera('my_module::packages') package { $packages: ensure => 'present', require => Exec['apt_update'] } } Notes: - The value associated in Hiera with key 'my_module::packages' is an array. - The value from Hiera is *not* interpolated into a string in the Package declaration (so it stays an array). - You use normal Hiera mechanisms (i.e. your data hierarchy) to assign the correct array of packages to each node. - You may find it useful to use the hiera_array() function (and flatten() the result) instead of the plain hiera() function. Either way gives you an array, but with hiera_array() you can collect package names from every level of your hierarchy instead of only from the highest-priority one that provides any. Note also that if you need different Package parameters for different package names, then you need a different approach. Your example does not exhibit a need for that, but if you should ever discover one then one way to address it would be with the create_resources() function (combined with appropriately-structured data). John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/05919e6c-998d-41c3-a4e7-9de9177e30cf%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.