Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCUMENT-793

Add additional information to the external facts documentation

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Normal
    • Resolution: Fixed
    • Component/s: None
    • Labels:
    • Template:
    • QA Risk Assessment:
      Needs Assessment

      Description

      I ran into an issue where a fact was not retrieving the correct value. The issue turned out to be that I was using:

      bar=Facter.value('foo')
      

      instead of:

      Facter.add('test_fact') do
        setcode do
          bar=Facter.value('foo')
        end
      end
      

      It would help if we could expand the external fact documentation to include some of the information from this excellent explanation a colleague offered as to why external facts need to be formatted correctly because of the way that Factor evaluates them:

      Fact evaluation basically works in two steps.

      1. Define all possible resolutions for a fact and score them. Each definition has two parts:
        1. Metadata / criteria to use for scoring
        2. A block of code (unexecuted) to be run ONLY if the fact "wins"
      2. Pick the highest-scored fact resolution (the winner), and execute it's code block to set the fact value

      The problem in your code is that you've pre-empted Facter's normal process by forcing it to choose a winner early, before all the possible resolutions had been defined. You put your Facter.value('datacenter') in the metadata / criteria section of your custom fact resolution.

      When Facter started reading defintions and reached this one, it was forced to stop, score all the definitions it knew about already, and pick a winner from them, in order to come back with a value for Facter.value('datacenter').

      Any definitions it hadn't finished reading in effect never made it into the race. So even if they would have won, it didn't matter. They got skipped, disqualified.

      Once Facter.value('datacenter') was resolved, the race was over. Any subsequent calls returned the early winner. No re-dos.

        Attachments

          Activity

            People

            Assignee:
            claire.cadman Claire Cadman
            Reporter:
            paul.schaffer Paul Schaffer
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Zendesk Support