8

I'm trying to determine what Puppet thinks the environment is on my agent nodes. Per the documentation I've configured the agent's environment in /etc/puppet/puppet.conf as such

[agent]
    environment = development

In order to view the environment I've found this code to add an environment fact to facter:

require 'puppet'

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

However, on one of my agent nodes, if I run sudo facter -p environment, the result is production. I've tried to manually set the environment temporarily via sudo puppet agent --environment development, however the result from facter is the same.

Any idea what's going on?

quickshiftin
  • 2,025
  • 5
  • 27
  • 41
  • Perhaps a [bug](http://projects.puppetlabs.com/issues/14716). I added *environment* to the *main* stanza and it works (after restarting puppet service). Putting the value beneath the *agent* stanza seems to have no effect. – quickshiftin Oct 25 '13 at 17:10
  • 1
    Environment is already passed to the server. You don't need to create a fact. – Zoredache Oct 25 '13 at 17:11
  • @Zoredache Seems like the environment wasn't even being set correctly to begin with. How else would I have seen that without the fact? – quickshiftin Oct 25 '13 at 17:23
  • Also, why would `sudo puppet agent --environment development` not be reflected via the fact? – quickshiftin Oct 25 '13 at 17:34
  • 3
    The puppet client sends some facts of its own that you don't see in facter. environment is one, The client version, and certificate name are other examples. You can put something like `notify {"environment = $::environment":}` on your master. – Zoredache Oct 25 '13 at 17:53
  • I'm really not creating the fact to use in a module etc on the master. Just trying to see what's going on w/ agent boxes. Seems a lot easier to have a fact that I can check on the agent, rather than having to view log output on the master... Either way, `sudo puppet agent --environment development` is still not working and I'm curious why. Ultimately I'd like to influence `hiera` environment checks which I believe are entirely local to agent nodes, so again, no need to consider the master in troubleshooting that I can see. – quickshiftin Oct 25 '13 at 19:29
  • You are **killing the old agent instances** before running `sudo puppet agent --environment ...` right? If you are trying do a one-type test you should use `puppet agent --test --environment ...` You can add `--debug` for even more details on the client. – Zoredache Oct 25 '13 at 19:51
  • `puppet agent --environment development` sets the environment for that one run, it does not change the configuration. It would not change the result of a subsequent `facter` command in any way. You should ***not*** be trying to set up a custom fact for `environment`. What are you trying to accomplish? If you're trying to check what `environment` is being used by the agent to get a catalog from the master, you should be looking at the inventory service or a notify resource as Zoredache mentioned. – Shane Madden Oct 25 '13 at 20:24
  • Thanks for the clarification on `puppet agent --environment development`. I'm simply trying to determine what the environment is on an agent. As I said I think the fact makes perfect sense for that. As I've discovered, the documentation appears to be inaccurate or there's a bug around *puppet.conf* environments. – quickshiftin Oct 25 '13 at 20:29

1 Answers1

8

Try puppet agent --configprint environment - that'll make sure it's using the [agent] block in the config file, which will also be used when the agent is getting a catalog from a master.

Shane Madden
  • 112,982
  • 12
  • 174
  • 248
  • Shouldn't the *agent* stanza inherit from the *main* stanza? That's what the [documentation](http://docs.puppetlabs.com/guides/configuring.html) says "The [main] config block is the least specific. Settings here are always effective, unless overridden by a more specific block." However, when I run this command the result is *production*, whereas if I use the fact in my question *development* is returned. Even when I try your command with the environment set beneath the *agent* stanza the result is *production* – quickshiftin Oct 25 '13 at 20:44
  • Yes, it can be set in either the main or agent block. It's not using the correct config file if the contents of the config file aren't in effect. Are you root? – Shane Madden Oct 25 '13 at 20:58
  • I know you *should* to be able to be able to set the environment in either location, but the fact doesn't seem to work 100% when set inside the *agent* stanza. I've been running the facter command via sudo. And just realized when running your command via sudo it returns *development*. Moreover it returns development when the environment is set in the *agent* stanza! Goodbye custom fact, hello next serverfault question (coming soon ;)) – quickshiftin Oct 25 '13 at 21:40
  • @quickshiftin Right - when you aren't root, then it's not using the `/etc/puppet/puppet.conf` file. – Shane Madden Oct 25 '13 at 23:55