File attributes inside template

19 views
Skip to first unread message

Trunet

unread,
Jun 14, 2012, 3:43:48 PM6/14/12
to puppet...@googlegroups.com
Hi,

I would like to know if I can use a File attribute inside a template. Is it possible?

Example:
A class with:
file { "/ssl/certificate.crt":
        source => "puppet:///modules/apache/certificate.crt",
        owner => root,
        group => apache,
        mode => 440,
        require => Class["apache::install"],
}

file { "/conf/apache/apache-system1.conf":
         ensure => present,
         content => template("apache/apache-system1.conf.erb"),
         require => [Class["apache::install"], File["/ssl/certificate.crt"]],
         notify => Class["apache::service::system1"],
}

On my template I want to have a line like this:
SSLCertificateFile /ssl/certificate.crt

using puppet file attribute directly(like this below that does not work obviously):
SSLCertificateFile <%= File["/ssl/certificate.cfg"].name %>

Thanks,

Wagner Sartori Junior

Nick Fagerlund

unread,
Jun 14, 2012, 5:44:54 PM6/14/12
to puppet...@googlegroups.com


On Thursday, June 14, 2012 12:43:48 PM UTC-7, Trunet wrote:
Hi,

I would like to know if I can use a File attribute inside a template. Is it possible?


No, you can't query resource attributes like that.

Instead, you should extract the string into a variable, then use the same variable in both places.

$certificate_path = '/ssl/certificate.cfg'

file {$certificate_path:
  ...
}

(Then, in the template:)
SSLCertificateFile <%= @certificate_path %>
Reply all
Reply to author
Forward
0 new messages