Uploaded image for project: 'Facter'
  1. Facter
  2. FACT-1085

Facter should not redirect stderr to stdout

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: FACT 3.0.1
    • Fix Version/s: FACT 3.0.2
    • Component/s: None
    • Labels:
      None
    • Template:
    • Story Points:
      2
    • Sprint:
      Client 2015-07-22

      Description

      Using this custom fact:

      Facter.add("pe_razor_server_version") do
        confine :osfamily => "Debian"
        setcode do
          Facter::Core::Execution.exec("dpkg-query -W --showformat='${Version}' pe-razor-server | cut -f1 -d'-'")
        end
      end
      

      In Facter 2.x, Facter doesn't redirect the command's stderr, so it gets printed directly to the terminal.

      # puppet agent -t
      Info: Retrieving pluginfacts
      Info: Retrieving plugin
      Info: Loading facts
      dpkg-query: no packages found matching pe-razor-server
      

      The pe_razor_server_version does not resolve. *This is the expected behavior.*

      In Facter 3.x, Facter incorrectly redirects the command's stderr into stdout, resulting in pe_razor_server_version resolving to "dpkg-query: no packages found matching pe-razor-server" (I'm assuming this outputs on stderr, but if it doesn't, this can easily reproduced with a non-existent first command in the pipe sequence too). This is the first bug.

      The second bug is that if dpkg-query (or any first command in a pipe sequence) is not found, then Facter::Core::Execution.exec treats it as a missing command and returns nil. Facter does this check for commands, but in this case the command is /bin/sh, which exists. An additional check is required to the arguments to /bin/sh (i.e. the original command given to Facter::Core::Execution::exec) and treat it as command missing.

      Note that we do not want to print the line "dpkg-query: no packages found matching pe-razor-server" to puppet's stderr, like Facter 2.x did. Instead, with Puppet's feature of redirecting Facter debug output, passing --debug to puppet will show more details, including this message from dpkg-query.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                scott.mcclellan Scott McClellan
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support