On Sat, Jan 03, 2009 at 05:12:24PM -0800, Jos Backus wrote:
> Untested:
>
> On Sat, Jan 03, 2009 at 04:55:41PM -0800, 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
>
> Try: $1.dup
>
> > setcode do
> > #{$6}
>
> Try: $6.dup
What I end up with is:
passwd = IO.readlines('/etc/passwd')
passwd.each do |line|
line =~ /(.*):(.*):(.*):(.*):(.*):(.*):(.*)/
Facter.add("home_#{$1.dup}") do
setcode do
$6.dup
end
end
end
which does exactly the same thing:
home_backup => /var/run/dbus
home_bin => /var/run/dbus
home_daemon => /var/run/dbus
home_debian-exim => /var/run/dbus
home_games => /var/run/dbus
home_gnats => /var/run/dbus
home_irc => /var/run/dbus
home_libuuid => /var/run/dbus
etc, etc.
/var/run/dbus is the home of the last /etc/passwd entry.
-Robin
--
They say: "The first AIs will be built by the military as weapons."
And I'm thinking: "Does it even occur to you to try for something
other than the default outcome?" -- http://shorl.com/tydruhedufogre
http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---