Ask Your Question

How to avoid hard coding node names

asked 2014-08-13 21:44:47 -0500

auerbecktj gravatar image

updated 2014-08-14 13:16:14 -0500

spuder gravatar image

I'm currently running an environment where we have multiple clusters (i.e. application nodes, database nodes, etc.) and have separate manifests for each. Currently within our manifests we are having to hardcode our nodenames (xxxdev,xxxstage,xxxprod). The problem with this is that we have a puppetmaster per environment which houses this code for each of our testing environments. So when we migrate our scripts, we have to manually touch each of these files to remove the xxxdev and replace it with xxxstage or xxxprod.

What I'm looking for is a more dynamic way to set our node names. Could we do something like set a variable called $pupenv='dev' or $pupenv='stage' in the site.pp manifest and then have nodenames set as follows in the rest of the manifests? :

node 'xxx$env' { and it would evaluate to xxxdev

or is there a way within hiera to set an array of servers (xxxprd1,xxxprd2) and then say :

node hiera('app') {

and it would populate for each app within that hiera variable

Any input would be appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-08-14 13:42:55 -0500

spuder gravatar image

updated 2014-08-15 13:19:20 -0500

You can use regular expressions to define your node names

node /^(foo|bar)\.example\.com$/ {
      include common

More likely, what you are looking for is directory environments

For this you would create separate directories like


Then on the nodes, you can choose what environment they are in either with your enc, or in the puppet.conf

If you want to keep your 3 separate puppet masters, you could try leveraging facter's ability to read in environment variables.

For example if you environment contains a string that starts with FACTER_ it is accessible from manifests.

$ export FACTER_FOO='production'

node "web-${::foo}"

This will then expand to 'web-production'

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-08-13 21:44:47 -0500

Seen: 142 times

Last updated: Aug 15 '14