| With the recent changes in PUP-10216, the agent stores the last used environment in last_run_summary.yaml. If the next run does not specify an environment on the CLI, then the last used environment always takes precedence over the environment specified in puppet.conf. For example, given:
# puppet agent -t --environment feature_branch |
# puppet agent -t
|
If the agent is allowed to specify its environment: Prior to PUP-10216, the second run would use the original configured environment from puppet.conf or default to "production". After PUP-10216, the second run uses the "feature_branch" environment. This is also true if the second run occurs in the background (systemd/cron), which is especially surprising. In cases where the agent is not allowed to specify its environment, the last used environment provides the same function that the node request did. So the agent's behavior before and after PUP-10216 is the same, assuming the agent pluginsync'ed the right set of facts and classification doesn't change between runs. This ticket proposes we make an exception for the agent-specified case so that the second run only uses the environment from the previous run if it was server-specified. Otherwise, the agent should start in its configured environment (from puppet.conf) or default to "production". So I think this means:
- If environment specified on CLI, use it
- If last environment was server-specified, use it
- Otherwise use our configured environment Puppet[:environment]
I think we can detect if the last environment was server-specified by saving both the initial environment and the converged environment. If those are different, then the server told us to use a different environment. If they are the same, then it doesn't matter if it's agent or server-specified, just use it. |