Puppet: file, template and variables

puppettemplate

I'm trying to create a file based on templates, but I'm getting an error that the template(s) cannot be found.

My directory setup is /etc/puppet/modules//templates/

Under templates, if have a directory for each host, plus a common template. Under the host directory I have a template specific to that host.

/server/puppet/modules//manifests/init.pp

class {

file { "/tmp/<file>":
    ensure  => present,
    content => template('<module>/${hostname}/default.erb', '<module>/common.erb'),
    audit   => content,
    notify  => File["/tmp/<file2>"],
}

file { "/tmp/<file2>":
    ensure => present,
    source => "/tmp/file",
    audit   => content,
}

}

when I run the puppet agent, I get the error on the content option of the first file statement. I don't know if the template function needs the templates directly under the template directory or if it's not interpreting the hostname variable correctly.

Best Answer

Variables aren't parsed inside single quotes. Use double quotes when you need to interpolate $variables.

https://puppet.com/docs/puppet/3.8/lang_datatypes.html#strings

Related Topic