Using fact to determine node environment

204 views
Skip to first unread message

John Kennedy

unread,
May 2, 2012, 6:59:49 AM5/2/12
to puppet...@googlegroups.com
We have a custom fact that we wrote to determine which (business) environment a specific server belongs to (test, stage, production).
We want to set up puppet environments (again, test, stage, and production).
Is it possible to use our custom fact to set which environment a node belongs to?
Thanks,
John

John Kennedy

R.I.Pienaar

unread,
May 2, 2012, 7:19:34 AM5/2/12
to puppet...@googlegroups.com
your only option at present is to write out puppet.conf using a template
with your fact

Dan Carley

unread,
May 2, 2012, 7:42:48 AM5/2/12
to puppet...@googlegroups.com
On 2 May 2012 12:19, R.I.Pienaar <r...@devco.net> wrote:
your only option at present is to write out puppet.conf using a template
with your fact

We use this approach. The very first run gets called with "--environment foo" and it sticks. "--environment" can then be called again if it needs to move to another environment/branch. "puppet.conf" simply contains:

# Make environment "sticky" with each run.
# Populated by `environment` variable from Facter.
environment = <%= @environment %>

Nigel Kersten

unread,
May 2, 2012, 11:10:16 AM5/2/12
to puppet...@googlegroups.com
Unless something broke it recently, I ran for years with a fact that returned ":environment" and didn't set it in puppet.conf at all.

 

John Kennedy

unread,
May 2, 2012, 11:15:02 AM5/2/12
to puppet...@googlegroups.com
 
Nigel,
Thanks for the response. How can I use that fact to set the environment of a node?
John

R.I.Pienaar

unread,
May 2, 2012, 11:18:17 AM5/2/12
to puppet...@googlegroups.com
yes, it broke. You'll get a mix of files from one environment and classes
from another etc, puppet.conf is the only option now

Nigel Kersten

unread,
May 2, 2012, 11:24:06 AM5/2/12
to puppet...@googlegroups.com
I think you're thinking of the ENC setting the environment, not a fact called 'environment' RI? 

R.I.Pienaar

unread,
May 2, 2012, 11:37:36 AM5/2/12
to puppet...@googlegroups.com
nope.

Nigel Kersten

unread,
May 2, 2012, 11:38:38 AM5/2/12
to puppet...@googlegroups.com


On Wed, May 2, 2012 at 8:37 AM, R.I.Pienaar <r...@devco.net> wrote:

> > Unless something broke it recently, I ran for years with a fact
> > that
> > returned ":environment" and didn't set it in puppet.conf at all.
>
> yes, it broke. You'll get a mix of files from one environment and
> classes
> from another etc, puppet.conf is the only option now
>
>
>
>
> I think you're thinking of the ENC setting the environment, not a
> fact called 'environment' RI?

nope.

Anyone got a bug # for this? 

R.I.Pienaar

unread,
May 2, 2012, 11:46:24 AM5/2/12
to puppet...@googlegroups.com


----- Original Message -----
> From: "Nigel Kersten" <ni...@puppetlabs.com>
> To: puppet...@googlegroups.com
> Sent: Wednesday, May 2, 2012 4:38:38 PM
> Subject: Re: [Puppet Users] Using fact to determine node environment
>
>
>
>
pretty sure there was one but couldnt find it so I just knocked up a quick test, this has been discussed to death in the past


.
├── development
│   ├── modules
│   │   └── test
│   │   ├── files
│   │   │   └── envtest
│   │   └── manifests
│   │   └── init.pp
│   └── site.pp
├── production
│   ├── modules
│   │   └── test
│   │   ├── files
│   │   │   └── envtest
│   │   └── manifests
│   │   └── init.pp
│   └── site.pp
├── puppet.conf
└── test.pp


test.pp has: include test


production init.pp has:


class test {
notify{"production test": }
file{"/tmp/envtest":
source =>"puppet:///modules/test/envtest"
}
}


development just changed the notify

when running with --enviornment this works:

% puppet apply --config puppet.conf --environment development test.pp
notice: development test
notice: /Stage[main]/Test/Notify[development test]/message: defined 'message' as 'development test'
notice: /Stage[main]/Test/File[/tmp/envtest]/ensure: defined content as '{md5}e42d5f60192d1f8f94ce446fff3113b0'
notice: Finished catalog run in 0.03 seconds
% cat /tmp/envtest
development

% puppet apply --config puppet.conf --environment production test.pp
notice: /Stage[main]/Test/File[/tmp/envtest]/content: content changed '{md5}e42d5f60192d1f8f94ce446fff3113b0' to '{md5}6f03617bce8a5d04fe97df572f273d05'
notice: production test
notice: /Stage[main]/Test/Notify[production test]/message: defined 'message' as 'production test'
notice: Finished catalog run in 0.03 seconds
% cat /tmp/envtest
production

same with a fact and here i am getting development code with production files:

% FACTER_environment=development puppet apply --config puppet.conf test.pp
notice: development test
notice: /Stage[main]/Test/Notify[development test]/message: defined 'message' as 'development test'
notice: Finished catalog run in 0.02 seconds
% cat /tmp/envtest
production

R.I.Pienaar

unread,
May 2, 2012, 11:53:38 AM5/2/12
to puppet...@googlegroups.com
should say I am on 2.6.x here, this may well have been fixed in 2.7.x

Nigel Kersten

unread,
May 2, 2012, 2:43:35 PM5/2/12
to puppet...@googlegroups.com
On Wed, May 2, 2012 at 8:53 AM, R.I.Pienaar <r...@devco.net> wrote:

> > > I think you're thinking of the ENC setting the environment, not a
> > > fact called 'environment' RI?
> >
> > nope.
> >
> >
> > Anyone got a bug # for this?
>
> pretty sure there was one but couldnt find it so I just knocked up a
> quick test, this has been discussed to death in the past

should say I am on 2.6.x here, this may well have been fixed in 2.7.x

That's the puzzling bit. It was definitely working for me in production in earlier 2.6.x days.

I just tested with 2.7.x and it's broken too.

I'll go hunting through the bug tracker today and update the bug or file a new one.

Frustrating. 
Reply all
Reply to author
Forward
0 new messages