using facter variables in filenames

419 views
Skip to first unread message

Tim Dunphy

unread,
Jan 29, 2014, 12:23:30 PM1/29/14
to puppet...@googlegroups.com
Hi All,

 I'm attempting to distribute TLS certs based on the $hostname fact in my config manifest like so:

class bacula::config {


  file { "/etc/bacula/bacula-fd.conf":
      notify  => Service["bacula-fd"],
      owner => "root",
      group => "root",
      mode => 0640,
      require => Package["bacula-client","bacula-common"],
      content => template("bacula/bacula_fd__config.erb"),
     }


    file { "/etc/pki/tls/private/$hostname.mydomain.com.key":
      notify  => Service["bacula-fd"],
      owner => "root",
      group => "root",
      mode => 04000,
      require => Package["bacula-client","bacula-common"],
      source => "puppet:///modules/$hostname/$hostname.mydomain.com.key",

     }

}

Correct me if I'm wrong, but should the above syntax not work?


Because I see when I try to run the config on the client site I get this error:

[root@puppet:/etc/puppet] #puppet agent --test
Info: Retrieving plugin
Info: Caching catalog for puppet.mydomain.com
Info: Applying configuration version '1391015907'
Notice: /Stage[main]/Bacula::Install/Exec[create_working_dir]/returns: executed successfully
Error: /Stage[main]/Bacula::Config/File[/etc/pki/tls/private/puppet.mydomain.com.key]: Could not evaluate: Could not retrieve information from environment production source(s) puppet:///modules/puppet/puppet.mydomain.com.key
Notice: /Stage[main]/Bacula::Service/Service[bacula-fd]: Dependency File[/etc/pki/tls/private/puppet.mydomain.com.key] has failures: true
Warning: /Stage[main]/Bacula::Service/Service[bacula-fd]: Skipping because of failed dependencies
Notice: Finished catalog run in 1.63 seconds


Can someone please offer an opinion as to why this may not be working?

Thanks
Tim
--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B

José Luis Ledesma

unread,
Jan 29, 2014, 12:30:51 PM1/29/14
to puppet...@googlegroups.com

You have to use {}.  So it should be something like

   source => "puppet:///modules/${::hostname}/${::hostname}.mydomain.com.key",

I've used :: too to avoid looking at the local scope.

Regards

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAOZy0e%3Dx%2BcFLjW%3D-H54cttNLV77bhdbNwSg0%3DLNWH7pSoiT3CQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

José Luis Ledesma

unread,
Jan 29, 2014, 12:33:27 PM1/29/14
to puppet...@googlegroups.com

Ups. Looking it again you forgot to set the module name in the puppet://

So the {} is not needed although I think is a good practice

El 29/01/2014 18:23, "Tim Dunphy" <bluet...@gmail.com> escribió:

Tim Dunphy

unread,
Jan 29, 2014, 1:39:52 PM1/29/14
to puppet...@googlegroups.com
Hey all,

Yup! You caught it. Managed to notice this as well, so forgive the intrusion on your day. 

But I was missing the module name. 


file { "/etc/pki/tls/certs/$hostname.mydomain.com.crt":
      notify  => Service["bacula-fd"],
      owner => "root",
      group => "root",
      mode => 04000,
      require => Package["bacula-client","bacula-common"],
      source => "puppet:///modules/bacula/$hostname/$hostname.mydomain.com.crt",

     }


That actually works! But thanks for the tip on using {} in my variables. I'll start using that now.

Thanks,
Tim



For more options, visit https://groups.google.com/groups/opt_out.

Johan De Wit

unread,
Jan 29, 2014, 3:35:57 PM1/29/14
to puppet...@googlegroups.com
On 01/29/2014 07:39 PM, Tim Dunphy wrote:
Hey all,

Yup! You caught it. Managed to notice this as well, so forgive the intrusion on your day. 

But I was missing the module name. 


file { "/etc/pki/tls/certs/$hostname.mydomain.com.crt":
      notify  => Service["bacula-fd"],
      owner => "root",
      group => "root",
      mode => 04000,
      require => Package["bacula-client","bacula-common"],
      source => "puppet:///modules/bacula/$hostname/$hostname.mydomain.com.crt",

     }


That actually works! But thanks for the tip on using {} in my variables. I'll start using that now.

Thanks,
Tim


On Wed, Jan 29, 2014 at 12:33 PM, José Luis Ledesma <joseluis...@gmail.com> wrote:

Ups. Looking it again you forgot to set the module name in the puppet://

So the {} is not needed although I think is a good practice


just start using ${variable} when used in a string (double quoted) . and also use explicit scoping.  It is a very good habit and you will only benefit from it.

( and everybody else, including you,  reading your code)




For more options, visit https://groups.google.com/groups/opt_out.


-- 
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer         (805008667232363)
Puppet Certified Professional 2013 (PCP0000006)
_________________________________________________________
 
Open-Future                 Phone     +32 (0)2/255 70 70
Zavelstraat 72              Fax       +32 (0)2/255 70 71
3071 KORTENBERG             Mobile    +32 (0)474/42 40 73
BELGIUM                     http://www.open-future.be
_________________________________________________________
 

Upcoming Events:

Puppet Fundamentals Training | http://www.open-future.be/puppet-fundamentals-training-4-till-6th-february

Puppet Introduction Course | http://www.open-future.be/puppet-introduction-course-7th-february

Zabbix Certified Training | http://www.open-future.be/zabbix-certified-training-10-till-12th-february

Zabbix for Large Environments Training | http://www.open-future.be/zabbix-large-environments-training-13-till-14th-february

Subscribe to our newsletter: http://eepurl.com/BUG8H


Tim Dunphy

unread,
Jan 29, 2014, 3:51:34 PM1/29/14
to puppet...@googlegroups.com
just start using ${variable} when used in a string (double quoted) . and also use explicit scoping.  It is a very good habit and you will only benefit from it.
( and everybody else, including you,  reading your code)


Thanks! I'll make sure to follow your advice. I appreciate your input.

Tim 



For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages