Chris's Blog

Devops Shokunin

Puppet source file trick

1 Comment »

The source parameter in the file type can take an array and will match on the first file present.

I find this useful for overriding configs for specific hosts without having to change any puppet code.
Puppet will search first for ${fqdn}.nginx.conf if that file does not exist then it will move through the array until it finds a file that does exist.
Make sure to always have a reasonable default configuration.

file {"/etc/nginx/nginx.conf":
  owner => "root",
  group => "root",
  mode => 644,
  source => ["puppet:///nginx/configs/${fqdn}.nginx.conf",
             "puppet:///nginx/configs/${custom_env}.nginx.conf",
             "puppet:///nginx/configs/default.nginx.conf"],
  require => Package["nginx"],
}

One Response

That is a fantastic tip, I love it. 🙂 This beats the repetition of other methods I’ve seen and is very simple. Thanks for sharing.