I'm trying to get something like this to work in my Puppet manifest:
if $hostname == 'host1' || $hostname == 'host2' {
# Modified config.txt for portrait mode.
file { '/boot/config.txt' :
ensure => present,
mode => '0755',
source => 'puppet://puppet/files/boot/config.txt.portrait',
}
} else {
# Normal config.txt for landscape mode.
file { '/boot/config.txt' :
ensure => present,
mode => '0755',
source => 'puppet://puppet/files/boot/config.txt.landscape',
}
}
However, this fails. What is the best way to, depending on the hostname, to include different files?
An alternative syntax would be to use a selector in your source parameter.
Building on what devicenull said, you can then shorten it further by using selective file source(s):
I've got many examples like these in my manifests where relatively static files are needed for a host type (not often down to hostname level), but definitely $domain, and a custom fact $site_location (external, datacentre, office, etc) is used extensively.
For what you're asking I'd use Case Statements.
Tuinslak!
We solved our problem like this:
We have two different types of chronyd configuration files: one for all the regular machines and one for all the DNS servers who act like a NTP server inside our network. We have a name convention here, that every DNS server has the hostname started with "sv-dns". So with the snippet above we can assure that every hostname, wich its name starts with "sv-dns" will receive the chrony.conf_server file and all other servers will receive the chrony.conf_client file.
If your hostname is fixed for example dnsmachine.some.domain you can use the example provided by @kwiksand:
Best regards,
Adail
I had to use "or" instead of ||: