1

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.

EEAA
  • 109,363
  • 18
  • 175
  • 245
Todd Strauch
  • 11
  • 1
  • 2
  • 2
    Please post the error you're getting. – EEAA Jul 31 '12 at 12:51
  • 2
    And if you can help it, use actual values rather than syntactically incorrect placeholders like `` and ``, because this distracts from the real issue. – larsks Jul 31 '12 at 12:56
  • If you run puppet in debug mode (`-d`), you'll get lots of diagnostic output and you'll probably be able to see if `$hostname` is expanding as you expect. – larsks Jul 31 '12 at 12:57
  • 1
    Variables aren't parsed inside single quotes. Use double quotes when you need to interpolate $variables. – czervik Jul 31 '12 at 15:36
  • Thanks czervik. The double quotes took care of the issue. Another example of "don't follow the documentation too closely". – Todd Strauch Aug 01 '12 at 10:17
  • @czervik, you mith want add your comment as an answer, since it seems to have solved Todd's issue. – Zoredache Aug 16 '12 at 05:50

1 Answers1

4

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

рüффп
  • 620
  • 1
  • 11
  • 25
czervik
  • 241
  • 1
  • 3