I''m testing custom fact precedence and am encountering issues, any help
would be appreciated.
I have a file containing the following data on ''most'' of my
servers and
built a fact (status) that displays the information
[root@localhost]# cat /dataFile
STATUS=good
[root@localhost]# facter status
good
However ''some'' of my servers do not contain this value and
therefore the
value of the fact is ''varianced''
[root@localhost]# cat /dataFile
[root@localhost]# facter status
varianced
I have another fact that checks for all the ''varianced'' items
and displays
their information:
[root@localhost]# cat /varianceFile
#syntax for this file:
# variance_<name of item> = <variance #> , <user id> ,
<date>
# example:
# variance_myTestName=0000,userFoo,0101130011
variance_status=0011,bob,0117130622
[root@localhost]# facter variance_status
0011,bob,0117130622
So, on all my servers I can parse the ''status'' fact and
determine:
1) which have a ''status'' of good
2) which have a ''status'' of varianced
and
3) if varianced, what the variance number is, who created the variance and
at what time the variance was created
Here''s my facter code:
[root@localhost]# cat facter/statusFacts.rb
#get server status from /dataFile
Facter.add("status") do
#this can be varianced so let''s check for that here. Note: all
facts
that can be varianced should have a weight less than 998
has_weight 99
if not Facter.value("variance_status").nil?
setcode {"varianced"}
else
setcode do
if Facter.value(:kernel) == ''Linux''
%x{/bin/grep "^STATUS=" /dataFile|/bin/cut -d\= -f2}.chomp
else
%x{/usr/bin/grep "^STATUS=" /dataFile|/usr/bin/cut -d\=
-f2}.chomp
end
end
end
end
#does the server have any variances
#set weight to 999 so it is parsed BEFORE facts which may depend on
''variances''
Facter.add("variance") do
has_weight 999
varianceExists = Facter::Util::Resolution.exec("grep ^variance_
/varianceFile 2>/dev/null")
varianceExists = varianceExists.strip
if not varianceExists.nil?
setcode do
"true"
end
else
setcode do
"false"
end
end
end
#enumerate variance names
#set weight to 998 so it is parsed BEFORE facts which may depend on
''variances''
varianceData = Facter::Util::Resolution.exec("grep ^variance_ /varianceFile
2>/dev/null")
varianceData = varianceData.strip
if not varianceData.nil?
varianceData.each_line do |line|
line = line.chomp
if not line.nil?
varianceName=line.split("=")[0]
varianceInfo=line.split("=")[1]
Facter.add(varianceName) do
has_weight 998
setcode do
varianceInfo
end
end
end
end
end
So, in keeping the code above as is, and therefore relying on the
''has_weight'' property, the "status" fact does not
get defined
[root@localhost]# facter|grep variance
variance => true
variance_status => 0011,userID,0117130622
If I run facter with ''--trace --debug'' all it says is
"value for status is
still nil".
However if I define the "variance_status" fact BEFORE the
"status" one then
it works as expected. But this doesn''t use the
''has_weight'' property.
[root@localhost]# facter|grep variance
status => varianced
variance => true
variance_status => 0011,bob,0117130622
So, how do I go about getting this to work. Is ''has_weight''
not working
because the facter ''value'' is being generated dynamically?
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/puppet-users/-/HzjiPi81wDMJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.