Feature #15972
openForeman fact name used for 'update_environment_from_facts' should be parametrizable
Description
New Puppet Code does not automatically export the "Environment" fact anymore. See http://projects.theforeman.org/issues/2205.
To allow clients to switch environments permanently when using Foreman as ENC and to support reporting the puppet client environment in Foreman dashboard, the ticket suggests adding a custom fact, which works for us.
However puppet has a very bad behaviour in 3.x, as custom facts can overwrite ENC set environment. See https://tickets.puppetlabs.com/browse/PUP-2630 for reference.
Currently the name of the fact used for "update_environment_from_facts" is hard coded to :environment, which causes a lot of side effects caused by the puppet bug above.
To provide reasonable compatibility, Foreman should support a new config option to define the fact name which will be used for "update_environment_from_facts" (e.g. puppet_environment). This way, clients side effects by setting the custom fact "environment" can be avoided while allowing the user who want's to "use update_environment_from_facts", to use this functionality by using another fact name as source for update_environment_from_facts.
The default value can be "environment" to provide 100% backward compatibility.
Files
Updated by Robert Heinzmann over 8 years ago
This works for us:
require 'puppet' Facter.add(:environment) do setcode do Puppet[:environment] end end
But we would rather use:
require 'puppet' Facter.add(:puppet_environment) do setcode do Puppet[:environment] end end
and specify the fact used for 'update_environment_from_facts' to be set to 'puppet_environment'. This avoids side effects.
Updated by Robert Heinzmann over 8 years ago
Attached the test results of the Puppet 3.8.6 environment selection using
- CMD line arguments to puppet agent
- custom facts specifying environment
- Puppet ENC specifying environment
!puppet 3 environment overwrite.png!
Updated by Robert Heinzmann over 8 years ago
- Related to Bug #2205: Environment doesn't exist in Puppet 3+ facts YAML added
Updated by Robert Heinzmann over 8 years ago
Actually I tested some more with Puppet 3.8 with Puppetserver 1.1.x and Agent.
With a dynamic environment fact like this:
require 'puppet' Facter.add(:environment) do setcode do Puppet[:environment] end end
The behaviour of puppet is "chaotic".
puppet agent --environment feature_xyz enc: environment: production
- Hiera: uses environment "feature_xyz" for hierdata content
- Puppet Server: uses environment "production" for code
This is really a bad idea. So providing the possibility to rename the fact, is really important.