From 9f4c5c6ac79821700bf4e6beee81f3d865396f4b Mon Sep 17 00:00:00 2001 From: Richard Clamp Date: Fri, 11 Mar 2011 12:23:23 +0000 Subject: (#6740) facter doesn't always respect facts in environment variables On an OSX host: $ facter operatingsystem Darwin $ facter_operatingsystem=Not_Darwin facter operatingsystem Not_Darwin But on a linux/solaris host: $ facter operatingsystem CentOS $ facter_operatingsystem=Not_CentOS facter operatingsystem CentOS As the operatingsystem fact resolution for linux-based kernels has higher precedence than the environment variable as it has more matching confines than the value from the environment variable. This patch adds from_environment to the resolution mechanism, which makes the resolution have an artificially high weight by claiming the length of its confines array is 1 billion. --- lib/facter/util/loader.rb | 1 + lib/facter/util/resolution.rb | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/facter/util/loader.rb b/lib/facter/util/loader.rb index 2d2d9e8..b6aa8de 100644 --- a/lib/facter/util/loader.rb +++ b/lib/facter/util/loader.rb @@ -90,6 +90,7 @@ class Facter::Util::Loader next if fact and env_name != fact Facter.add($1) do + from_environment setcode { value } end diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb index 4a99c35..2ca2447 100644 --- a/lib/facter/util/resolution.rb +++ b/lib/facter/util/resolution.rb @@ -85,17 +85,29 @@ class Facter::Util::Resolution end end + # Say this resolution came from the environment + def from_environment + @from_environment = true + end + # Create a new resolution mechanism. def initialize(name) @name = name @confines = [] @value = nil @timeout = 0 + @from_environment = false end # Return the number of confines. def length - @confines.length + # If the resolution came from an environment variable + # say we're very very sure about the value of the resolution + if @from_environment + 1_000_000_000 + else + @confines.length + end end # We need this as a getter for 'timeout', because some versions -- cgit