puppetlabs/facter — pull request #570 by joshcooper (2013-12-06 07:52:22+00:00)
Title: (#22944) External facts are executed many, many times

PR #569 needs to be merged first, as external script-based facts don't work on 2003.

Previously, facter would load every external fact many, many times. For executable facts, e.g. powershell, this means executing the fact. For text based facts, it means reading the file, and parsing its output. On Darwin, it was common for facts to be executed 6 times; on Windows, 19 times.

The problem occurs whenever facter requires a file, e.g. `ec2.rb`, which references another fact, e.g. `:macaddress` outside the body of any resolution, and facter has not yet required `macaddress.rb`.

For example, the following will cause all external facts to be loaded:

if Facter.value(:macaddress)
Facter.add(:ec2) do
...
end
end

Note that this is triggered because macaddress comes after ec2. Similarly, `blockdevices.rb` references the `:kernel` fact outside of any resolution, so that's another round of external fact evaluation.

This commit keeps adds a boolean flag to ensure we only execute external facts once.