Splat operator on file resource Error

4 views
Skip to first unread message

Martin Alfke

unread,
Apr 29, 2020, 1:39:43 PM4/29/20
to Puppet Users
Hi,

we want to make use of the splat operator and extend the list of parameters:

#site/profile/manifests/files.pp
class profile::files (
Hash $files = {},
){
$files.each |String $key, Hash $params| {
$_template = $params['template']
$_value = delete($params, 'template')

notify { 'template':
message => $_template,
}
notify { '_value':
message => $_value,
}

file { $key:
* => $_value,
content => epp($_template),
}
}
}

#data/common.yaml
---
profile::files::files:
'/tmp/foo':
ensure: file,
mode: '0644'
template: 'profile/file_template.epp'

Puppet agent run compains:

Error: Failed to apply catalog: Validation of File[/tmp/foo] failed: You cannot specify more than one of content, source, target (file: /etc/puppetlabs/code/environments/production/site/profile/manifests/files.pp, line: 15)

When removing the file resource, the notify output looks OK:

Notice: profile/file_template.epp
Notice: /Stage[main]/Profile::Files/Notify[template]/message: defined 'message' as 'profile/file_template.epp'
Notice: {"ensure"=>"file,", "mode"=>"0644"}
Notice: /Stage[main]/Profile::Files/Notify[_value]/message: defined 'message' as {
'ensure' => 'file,',
'mode' => '0644'
}
Notice: Applied catalog in 36.38 seconds

What am I missing or doing wrong?

Thanks,
Martin

Reply all
Reply to author
Forward
0 new messages