On May 30, 2010, at 1:57 AM, William Van Hevelingen wrote:

Hello All,

I have a facter question, is the use of ruby environmental variables encouraged or discouraged? I noticed that path.rb uses the ruby ENV object, but id.rb does not use it. However, if id.rb did use it then it could be reduced to 5 lines like so:

Facter.add(:id) do
    setcode do
        ENV['USER']
    end
end

Is there any particular reason that 'whoami' (Linux) and 'id' (Solaris) are used instead?

Here is some custom facts i made for windows. What do you think?

  1 # Windows specific facts
  2
  3 Facter.add(:homeshare) do
  4     confine :kernel => %w{Windows}
  5     setcode do
  6         ENV['HOMESHARE']
  7     end
  8 end
  9
 10 # Doesn't notice if its a roaming profile
 11 Facter.add(:userprofile) do
 12     confine :kernel => %w{Windows}
 13     setcode do
 14         ENV['USERPROFILE']
 15     end
 16 end
 17
 18 Facter.add(:appdata) do
 19     confine :kernel => %w{Windows}
 20     setcode do
 21         ENV['APPDATA']
 22     end
 23 end
 24
 25 Facter.add(:deploydate) do
 26     confine :kernel => %w{Windows}
 27     setcode do
 28         ENV['DEPLOY_DATE']
 29     end
 30 end

Seems pretty reasonable, although it almost seems worth adding a special hook:

Facter.envfact(:deploydate) { confine :kernel => %w{Windows} }

Which just does the above, but skips most of the duplication.

In general, the reason I've always avoided relying on ENV is that it's so easy for the data to not be right at different times, at least I think I've experienced that. It's always tough to track whether a given ENV variable is overwriteable, guaranteed, always set, etc.

--
The people who are regarded as moral luminaries are those who forego
ordinary pleasures themselves and find compensation in interfering
with the pleasures of others. -- Bertrand Russell
---------------------------------------------------------------------
Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199

--
You received this message because you are subscribed to the Google Groups "Puppet 
Developers" 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-dev?hl=en.

Reply via email to