On Friday, October 17, 2014 8:05:39 AM UTC-5, Andreas Dvorak wrote:
>
> Dear all,
>
> I would like to use the file resource to supply a host specific file. If
> it does exist choose it and if not create a file from a template.
> I tried this, but then /mnt/motd needs to be on all server.
>
> $a = file("/mnt/motd/motd-${::hostname}",'/dev/null')
> if($a != '') {
> file {$config_file:
> ensure => 'file',
> owner => 'root',
> group => 'root',
> mode => '0644',
> source => "puppet:///motd_files/motd/motd-${::hostname}",
> }
> }
> else {
> file { $config_file:
> ensure => 'file',
> owner => 'root',
> group => 'root',
> mode => '0644',
> content => template($template),
> }
> }
>
>
No, in that case /mnt/motd/* has to be on the machine that builds the
catalog, as that's where all Puppet functions will be evaluated. Since you
are using a puppetmaster for that purpose, that's where the files need to
be. I'd probably write it like this, though:
$a = file("/mnt/motd/motd-${::hostname}",'/dev/null')
file {$config_file:
ensure => 'file',
owner => 'root',
group => 'root',
mode => '0644',
content => $a ? { '' => template($template), default => $a }
}
John
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/3688cefa-b2f7-4733-94e9-96aad2e56455%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.