On Sep 10, 9:30 am, Jeff <[EMAIL PROTECTED]> wrote:
> On Sep 10, 8:27 am, Jeff <[EMAIL PROTECTED]> wrote:
>
>
>
> > I was hoping to get some guidance on my first fact. I'd like to create
> > a global configuration file that contains default values that I can
> > reference in multiple classes. In other words, I'd like one source
> > for, say, JAVA_HOME but I'd like to reference it in my java and
> > profile classes.
>
> > The configuration file would look like this:
>
> > java_home=/usr/java/jdk1.5.0_15
> > jboss_home=/usr/local/jboss
>
> > [etc]
>
> > I'd like the fact to read the file and assign the value to a variable
> > with the same name as the key, i.e.,
>
> > $java_home = "/usr/java/jdk1.5.0_15"
> > $jboss_home = "/usr/local/jboss"
>
> > [etc]
>
> Okay, I took a stab at this. Here's my code:
>
> key = nil
> val = nil
> test = {}
> File.open("/var/puppet/modules/globals.conf").each do |line|
> key,val = line.split(/=/)
> if key != nil && val != nil
> test[key] = val
> key = nil
> val = nil
> end
> end
> test.each { |name,fact|
> Facter.add(name) do
> setcode do
> fact
> end
> end
>
> }
>
> Unfortunately, it doesn't work. When I add print statements inside the
> test.each loop, I get values for 'name' and 'fact' HOWEVER, when I run
> it without those print statements I get nothing. I'm stumped.
>
> Jeff
This is a scope issue: If I do this in my array iteration:
test.each { |name,fact|
Facter.add(name) do
print name+"=>"+fact
setcode do
fact
end
end
}
name and fact print
BUT if I do this:
test.each { |name,fact|
Facter.add(name) do
setcode do
print name+"=>"+fact
fact
end
end
}
They do NOT print. Any ideas??
Jeff
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---