On Jan 3, 2009, at 6:55 PM, Robin Lee Powell wrote:

>
>
> I'm trying to create a bunch of Facter facts in a loop.  The code
> inside is evaluated at some weird time, *out of order*, and I don't
> know enough Ruby to fix it.  The goal is to get access to user
> homedirs, because I can't figure out any other way to do that in
> Puppet.
>
> Here's a few tries:
>
>      passwd = IO.readlines('/etc/passwd')
>      passwd.each do |line|
>          line =~ /(.*):(.*):(.*):(.*):(.*):(.*):(.*)/
>          Facter.add("home_#{$1}") do
>              setcode do
>                  #{$6}
>              end
>          end
>      end

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. :)

Yes, I know you already found a solution, but this is more a ruby  
question than a Puppet/Facter question, and I figure it's worth  
pointing out the correct solution.


-- 
Health is merely the slowest possible rate at which one can die.
---------------------------------------------------------------------
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