| The problem is the agent makes a node request to ask the server which environment it is supposed to be in. This is routed to puppet's indirected_routes logic, which handles all indirected REST requests. That code raises if the requested environment doesn't exist on the master. Generally that's a good thing, because we want a valid environment from which to serve plugins, catalogs, etc. But it doesn't make sense to force the agent to specify an environment that must exist on the master in order to ask the question "which environment should I be in". I think the ideal thing is to have a different REST API for asking the environment question. It should probably take the agent's current environment and facts (so the ENC doesn't need to get cached values from puppetdb, which may not exist yet), and return the server-specified environment, instead of a node object and all of its facts, which the agent already knows. The returned environment might be the same as what the agent is already in, if the agent is allowed to choose. Another option is to special case the node request, so if the requested environment doesn't exist on the server, have it fallback to a known good environment that does exist on the server, like:
configured_environment = Puppet.lookup(:environments).get(environment) |
if configured_environment.nil? |
configured_environment = Puppet.lookup(:current_environment) if indirection_name == 'node' |
else |
configured_environment = configured_environment.override_from_commandline(Puppet.settings) |
params[:environment] = configured_environment |
end
|
However that's a bit of a hack and we have to be careful about now allowing environments to be enumerated by an unauthenticated user. |