Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Thanks for the suggestion. IRL the use-case is a bit more complex than outlined here. The file resource is used within create_resources() to create files. The majority of files is created without templates, but in one specific case a template is used to iterate over a hash. Therefore I have to pass the template function to the the content-parameter in the file resource.
Otherwise your suggestion would have certainly worked.

So I try to reduce this code

# Puppet
class test() {

$files = {
  'file1' => {
    ensure => file,
    content => 'Some string',
  },
  'file2' => {
    ensure => file,
    content => template('test/template.erb'),
  },
}

create_resources(file, $files)

}

into (not working):

# Puppet
class test(
  $files,
) {
  create_resources(file,$files)
}

# Hiera
---
test::files:
  file1:
    ensure: file
    content: Some string
  file2:
    ensure: file
    content: template('test/template.erb')

it feels to me like this is something that should be doable, but I can neither find any technical support for that claim, nor reason why. Quite the opposite. Everything I know and read about Hiera and Puppet tells me it should not work (and it does not either).

So unless somebody knows a workaround this, I'll change my question: is there a more elegant way to do this?