summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Clamp <richardc@unixbeard.net>2011-03-11 12:23:23 +0000
committerJames Turnbull <james@lovedthanlost.net>2011-04-06 03:46:49 +1000
commit9f4c5c6ac79821700bf4e6beee81f3d865396f4b (patch)
tree474ed94a995ea09161f80df07648c2698a28a5db
parent7441b32f9e062f9ca73c9d452f0559aa866e0277 (diff)
downloadfacter-9f4c5c6ac79821700bf4e6beee81f3d865396f4b.tar.gz
facter-9f4c5c6ac79821700bf4e6beee81f3d865396f4b.tar.xz
facter-9f4c5c6ac79821700bf4e6beee81f3d865396f4b.zip
(#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.
-rw-r--r--lib/facter/util/loader.rb1
-rw-r--r--lib/facter/util/resolution.rb14
2 files changed, 14 insertions, 1 deletions
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