On Jan 8, 2009, at 3:58 PM, Jos Backus wrote:

>
> On Thu, Jan 08, 2009 at 12:41:14AM -0600, Luke Kanies wrote:
>> The problem here is that the block passed to 'setcode' isn't run  
>> until
>> later, at which point $6 is set to the last user's homedir.  Try  
>> this:
>>
>> Facter.add("...") do
>>   homedir = $6 # dereference immediately
>>   setcode { homedir }
>> end
>>
>> This works because 'homedir' is local to each fact definition,  
>> whereas
>> $6 is global.  At least, it *should* work. :)
>
> I figured the $6.dup would create a local copy. Guess it works  
> differently for
> globals, or I'm missing something obvious. I didn't actually look at  
> what
> setcode does, but that explains it.

It does create a local copy -- but it only creates the local copy  
after $6 has been set to a single value (the last one).  Remember that  
the setcode block is lazy-evaluated; it's evaluated when the fact  
value is asked for, rather than when the fact is defined.

This is partially why I recommend fact values be calculated  
dynamically rather than having a setup block that statically  
calculates a bunch of values and defines facts with those values; if  
the value changes over time (e.g., you hot-plug a disk and facter is  
counting disks) then dynamically calculated values are right but  
values only calculated on startup are wrong.


-- 
I had a linguistics professor who said that it's man's ability to use
language that makes him the dominant species on the planet. That may
be. But I think there's one other thing that separates us from animals.
We aren't afraid of vacuum cleaners. --Jeff Stilson
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to