puppetdb missing environment fact

246 views
Skip to first unread message

james.e...@fasthosts.com

unread,
Dec 4, 2013, 5:04:53 AM12/4/13
to puppet...@googlegroups.com
Hi,

I'm seeing something rather strange with puppetdb (1.5.2) in regards to the environment fact.

On my puppetdb host:

If I run the following query:

curl -G 'http://localhost:8080/v3/facts' --data-urlencode 'query=["=", "name", "environment"]'

I would expect to receive the environment fact for every node that I'm managing with puppet (>500).

However, that query only returns 11 nodes.  These 11 nodes are running puppet 2.7.22.

I am in the process of upgrading puppet to 3.3.2 from 2.7.22.

All of the nodes running 3.3.2 are missing the environment fact from puppetdb.  All the 2.7.22 nodes have the environment fact stored.

Can anyone think of a reason why the environment fact is missing for my 3.3.2 nodes?

J

Luke Bigum

unread,
Dec 4, 2013, 7:45:04 AM12/4/13
to puppet...@googlegroups.com
'environment' is not a Fact:

laptop:~$ sudo facter -p environment
laptop:~$ 

It is a configuration parameter of Puppet. I'm not sure why older 2.7 hosts would be reporting it as a Fact to PuppetDB, unless in 2.7 all top scope variables were sent this way.

You could use a Fact to pull out what environment an Agent *would* run with using this Fact code:

#Get the configured environment out of puppet.conf
begin
    puppet_environment = ''

    File.open('/etc/puppet/puppet.conf').each do |line|
        if line =~ /^\s*environment\s*=\s*(\S+)/
            puppet_environment = $1
        end
    end

    Facter.add(:puppet_environment) do
        setcode do
            puppet_environment
        end
    end
rescue
    Facter.warn("puppet_environment.rb failed: #{$!}")
end

james.e...@fasthosts.com

unread,
Dec 4, 2013, 9:27:09 AM12/4/13
to puppet...@googlegroups.com
Thanks Luke. 

I just found a bug report describing that this behaviour has changed in 3.x http://projects.puppetlabs.com/issues/17692

For me, being able to determine the agent environment is very useful.
We use git for the Puppet manifests and each branch is an environment.
So we'll create new branches to test and deploy new features.
Then when it's ready to go live to all nodes, we'll merge that branch back into master and remove the feature branch.
I rely on being able to query puppetdb or puppet-dashboard to find out which nodes are using environment X, so I can safely remove a branch once there are no nodes using it.

We also manage Puppet with Puppet and set the environment in puppet.conf based on the current environment.  This does still work as the environment is available in the manifests.

I also found the following code (at https://groups.google.com/forum/#!topic/puppet-users/AM1o4Khlotofor turning environment into a fact.
Including it here in case it's useful to others.

require 'puppet'

Facter.add('environment') do
  setcode do
    Puppet[:environment]
  end
end


J

Reply all
Reply to author
Forward
0 new messages