I have a custom puppet module for setting up Apache web server and I use templates to copy the configurations. We have different environments like production, Quality Assurance, Integration testing.

Each environment has one or more servers. The template uses variables based on these environments, and this ensures usage of same template file across all environments instead of using different environment specif files

So far i came to know that we can use {environment}.yaml type files in heira, which I don't prefer since I don't want to maintain two set of files for the environments like production.yaml and qa.yaml

What is the best practice to achieve this scenario?

  1. My view is that we assign environments of host in /etc/puppet/manifest/site.pp
  2. Where should we maintain environment specific variables (like domain=mysite.qa.example.com). Is this packaged in facts inside the module based on environment from site.pp for the node or is it maintained as node specific config in /etc/facter/facts.d/ on every node?

Is there a working example for the above.


The correct way to manage environment-specific data is to use Hiera - Hiera's purpose is to separate configuration data (e.g. domains, IP addresses) and logical Puppet code. If you have similar environments, duplication of configuration is expected.

You can use a static fact to determine the environment, and use %{::environment} (for Puppet3) or %{facts.environment} (for Puppet4) to access this within your Hiera structure.

Your modules should use parametisation to allow Hiera to pass values into the classes.

To store a static fact, create a file in /etc/facter/facts.d (create the directory if necessary) with the content environment=production, example:

odin ~ # echo 'environment=production' >> /etc/facter/facts.d/env.txt
odin ~ # facter -p environment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.