Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'd like to use the environments feature of Puppet in my.. environments. We differentiate between environments via hostname, e.g. prod-web1, stg-web1. I know I can use regex to match these in a single environment, but I'd rather use the actual environments functionality to allow module updates to be propagated through each environment.

From my understanding there are two ways to do this, and both ways have some problems;

-I can set the environment variable in the puppet agent's config. This requires interacting with each host. Obviously this could be trivially managed with Puppet, but the first run will apply the default production configs, and I'd really prefer if it didn't.

-I can define the environment variable when running the agent, but I would need to stick the agent in cron to specify that, and I'd lose the benefits of puppet's built-in splay.

How can I peg a box to an environment based upon its hostname?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Both options.

What I do for this is have Puppet managing the puppet.conf, and Hiera data for the node configured with which environment it's supposed to be in (whereas you'll be using a regex on the hostname to determine this).

To avoid the problem of applying production config on the first run, I avoid letting it do a run until I'm able to kick off that first run manually (by not signing the cert until I'm ready), then by doing the first run with puppet agent --test --environment staging - that'll do the staging environment explicitly for this run, as well as modifying the puppet.conf with the correct configuration for future runs.

share|improve this answer
    
Another option that I've considered implementing is to have the default environment be something that just reads from Hiera (or whatever) and sets the real environment. I'd name it "bootstrap" or something like that. (Note that I haven't actually done this, but I think it should work.) –  asciiphil Jun 26 '13 at 18:12
    
@asciiphil Oh yeah, that would be a good approach! –  Shane Madden Jun 26 '13 at 19:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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