Jira (PUP-10847) "puppet facts show fact" output differs from "facter fact"

0 views
Skip to first unread message

Clay Caviness (Jira)

unread,
Jan 5, 2021, 4:08:03 PM1/5/21
to puppe...@googlegroups.com
Clay Caviness created an issue
 
Puppet / Bug PUP-10847
"puppet facts show fact" output differs from "facter fact"
Issue Type: Bug Bug
Affects Versions: PUP 7.1.0
Assignee: Unassigned
Components: UX
Created: 2021/01/05 1:07 PM
Priority: Normal Normal
Reporter: Clay Caviness

Puppet Version: 7.1
OS Name/Version: macOS 11.1

The output of "puppet facts show somefact" is not the same as "facter somefact", as it returns JSON, which requires subsequent parsing to get the the fact value.

We use "facter --puppet somefact" quite a bit in non-puppet code, such as shell and python scripts and other internal management utilities. This is a strongly complicating issue in a migration from facter 3/puppet 6 to facter 4/puppet 7: "facter --puppet" no longer works in Facter 4, and I believe "puppet facts show somefact" only works in Puppet 7.

This will mean all the various places we use "facter --puppet somefact" will have to have a case on the puppet version and then call "facter --puppet somefact" or "puppet facts show somefact" as appropriate. And we'll have to do extra processing on the output of "puppet facts show", as it sends JSON.

Desired Behavior:

$ puppet facts show facterversion
4.0.47
$ facter facterversion
4.0.47

Actual Behavior:

$ puppet facts show facterversion

Unknown macro: { "facterversion"}

$ facter facterversion
4.0.47

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Clay Caviness (Jira)

unread,
Jan 5, 2021, 4:22:03 PM1/5/21
to puppe...@googlegroups.com
Clay Caviness updated an issue
Change By: Clay Caviness
*Puppet Version:* {{7.1}}
*OS Name/Version:* macOS 11.1

The output of "{{puppet facts show _somefact_}}" is not the same as "{{facter _somefact_}}", as it returns JSON, which requires subsequent parsing to get the the fact value.

We use "{{facter --puppet _somefact_}}" quite a bit in non-puppet code, such as shell and python scripts and other internal management utilities. This is a strongly complicating issue in a migration from facter 3/puppet 6 to facter 4/puppet 7: "{{facter --puppet}}" no longer works in Facter 4, and I believe "{{puppet facts show _somefact_}}" only works in Puppet 7.

This will mean all the various places we use "{{facter --puppet _somefact_}}" will have to have a case on the puppet version and then call "{{facter --puppet _somefact_}}" or "{{puppet facts show _somefact_}}" as appropriate. And we'll have to do extra processing on the output of "{{puppet facts show}}", as it sends JSON.

*Desired Behavior:*
{quote}

$ puppet facts show facterversion
4.0.47
$ facter facterversion
4.0.47
{quote}

*Actual Behavior:*
{quote}

$ puppet facts show facterversion
\ {
  "facterversion": "4.0.47"
}
\ $ facter facterversion
4.0.47
{quote}

Clay Caviness (Jira)

unread,
Jan 5, 2021, 4:23:03 PM1/5/21
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Jan 5, 2021, 6:49:04 PM1/5/21
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-10847
 
Re: "puppet facts show fact" output differs from "facter fact"

It makes sense to me to have facter4 facter --puppet <name> emit the value for a single fact in the same way as facter3/puppet6, so that users can easily upgrade.

I'm less certain about cases where multiple fact values are generated, because the output format is non-standard. For example, given multiple fact names:

$ facter -p osfamily virtual
osfamily => RedHat
virtual => vmware

Or structured facts:

$ facter -p os
{
  architecture => "x86_64",
  family => "RedHat",
  hardware => "x86_64",
  name => "RedHat",
  release => {
    full => "8.0",
    major => "8",
    minor => "0"
  },
  selinux => {
    enabled => false
  }
}

Trevor Vaughan (Jira)

unread,
Jan 5, 2021, 7:00:05 PM1/5/21
to puppe...@googlegroups.com

I'd be happy with something more shell-friendly.

For instance:

  • Single Fact => Just the Value
  • Complex Fact => JSON
  • Multi Fact => Something easy to parse (single value separator would be good so it can be run through cut)

It's a bit confusing, but the 90% use case is a single fact for scripting. Facter knows what it's returning so this shouldn't be too bad to implement.

Clay Caviness (Jira)

unread,
Jan 7, 2021, 10:28:04 AM1/7/21
to puppe...@googlegroups.com

Tangential to this, the timing of these changes is going to complicate and slow migration to Puppet 7/Facter 4.

Many folks use

{facter -p fact} in various scripts and other tools. With puppet 6/facter 3, {puppet facts show fact} isn't workable, only {facter -p fact}

. Puppet 7 adds a (mostly; this bug aside) working

{puppet facts show fact}. However, Puppet 7 requires Facter 4, which fully deprecates {facter -p fact}. In order to effect the upgrade from Puppet 6 to Puppet 7 (and Facter 4), all places where {facter -p fact} is used will need to first check what version of Puppet is installed, and then call {facter -p fact} or {puppet facts show fact}

as appropriate. And if the output of

{puppet facts show} isn't changed to match {facter -p}, additional logic will be needed to handle the extra parsing required.

I expect it's too late for this, but it would have eased things considerably if there was an overlap during which both {facter -p} and {puppet facts show}

worked (with the same output, of course), say by having Puppet 7 support Facter 3 and 4. Then the process would be simpler, as we could update to Puppet 7, roll that out, then update tooling to use

{puppet facts show}

everywhere, roll those out, then update to Facter 4 (by which time all uses of

{facter -p}

have been fixed).

Oana Tanasoiu (Jira)

unread,
Jan 8, 2021, 6:45:03 AM1/8/21
to puppe...@googlegroups.com

Oana Tanasoiu (Jira)

unread,
Jan 8, 2021, 6:45:03 AM1/8/21
to puppe...@googlegroups.com
Oana Tanasoiu updated an issue
Change By: Oana Tanasoiu
Sub-team: ghost
Team: Night's Watch

Oana Tanasoiu (Jira)

unread,
Jan 8, 2021, 6:47:03 AM1/8/21
to puppe...@googlegroups.com

Bogdan Irimie (Jira)

unread,
Jan 12, 2021, 2:42:03 AM1/12/21
to puppe...@googlegroups.com

Bogdan Irimie (Jira)

unread,
Jan 12, 2021, 2:42:04 AM1/12/21
to puppe...@googlegroups.com

Oana Tanasoiu (Jira)

unread,
Jan 12, 2021, 10:06:02 AM1/12/21
to puppe...@googlegroups.com

Bogdan Irimie (Jira)

unread,
Jan 13, 2021, 9:04:03 AM1/13/21
to puppe...@googlegroups.com
Bogdan Irimie updated an issue
Change By: Bogdan Irimie
Sprint: ghost-13.01.2020 , ready for triage 3

Gheorghe Popescu (Jira)

unread,
Jan 14, 2021, 4:15:04 AM1/14/21
to puppe...@googlegroups.com

Oana Tanasoiu (Jira)

unread,
Jan 18, 2021, 2:26:04 AM1/18/21
to puppe...@googlegroups.com
Oana Tanasoiu updated an issue
Change By: Oana Tanasoiu
Release Notes: Bug Fix
Release Notes Summary: Description of the problem: The output format is different between Facter and puppet facts when a query for a single fact is provided:
~~ puppet facts facterversion
{ "facterversion": "4.0.47" }
vs
~~ facter facterversion
4.0.47
Description of the fix:
Added --value-only command argument:
When there is a single query, only display the value of the fact without it's name:
~~ puppet facts facterversion --value-only
"4.0.47"
Also this generates a warning message if the argument is used with multiple queries or with no query at all:
puppet facts show facterversion os --value-only
Warning: Incorrect use of --value-only argument! The argument can only be used when querying for a single fact

Added flat render format:
When there is a query for a simple fact:
puppet facts show facterversion --render-as flat
facterversion=4.0.47
and with --value-only
puppet facts show facterversion --render-as flat --value-only
4.0.47

When there is a query for a more complex fact (ex. os) the output will be:

~~ puppet facts os --render-as flat
os.architecture=x86_64
os.family=Darwin
os.hardware=x86_64
os.macosx.build=18G95
os.macosx.product=Mac OS X
os.macosx.version.full=10.14.6
os.macosx.version.major=10.14
os.macosx.version.minor=6
os.name=Darwin
os.release.full=18.7.0
os.release.major=18
os.release.minor=7
and with --value-only

~~ puppet facts os --render-as flat --value-only
architecture=x86_64
family=Darwin
hardware=x86_64
macosx.build=18G95
macosx.product=Mac OS X
macosx.version.full=10.14.6
macosx.version.major=10.14
macosx.version.minor=6
name=Darwin
release.full=18.7.0
release.major=18
release.minor=7
For multiple user queries the output is :

~~ puppet facts show os.name facterversion --render-as flat
facterversion=4.0.47
os.name=Darwin
When the result is an array, the index of each element is also displayed:

~~ puppet facts show processors.models --render-as flat
processors.models.0=Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
processors.models.1=Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
processors.models.2=Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
processors.models.3=Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
processors.models.4=Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
processors.models.5=Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
processors.models.6=Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
processors.models.7=Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
~~ puppet facts show networking.interfaces.interface_name.bindings6 --render-as flat --value-only
0.address=fe80::...
0.netmask=ffff:ffff:ffff:ffff::
0.network=fe80::
0.scope6=link

Claire Cadman (Jira)

unread,
Jan 20, 2021, 5:23:04 AM1/20/21
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages