Jira (FACT-1875) Unable to use "confine" with structured facts -- documentation is incorrect

14 views
Skip to first unread message

Chris Butler (JIRA)

unread,
Aug 17, 2018, 8:26:03 AM8/17/18
to puppe...@googlegroups.com
Chris Butler updated an issue
 
Facter / Bug FACT-1875
Unable to use "confine" with structured facts -- documentation is incorrect
Change By: Chris Butler
Summary: Unable to use "confine" with structured facts -- documentation error is incorrect
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Chris Butler (JIRA)

unread,
Aug 17, 2018, 8:30:04 AM8/17/18
to puppe...@googlegroups.com
Chris Butler updated an issue
I've been attempting to {{confine}} some facts using structured facts, as described in [the documentation here|https://puppet.com/docs/facter/3.11/custom_facts.html#confining-facts]. However, neither the first method described in the docs seems documentation using Facter.value does not seem to actually work with the current version of facter :

{code}
==> oscheck_codeblock.rb <==
Facter.add(:oscheck_codeblock) do
confine :os do |os|
  os['id']
== 'Debian'
end

setcode do
  'fact value'
end
end

==
> oscheck_factervalue.rb <==
Facter.add(:oscheck_factervalue) do
confine Facter.value(:os)['
distro'][' id'] => 'Debian'

setcode do
  'fact value'
end
end
{code}

Running facter with FACTERLIB pointed at the location of the above
two files file gives:

{code}
2018-08-17 13:
21 28 : 09 22 . 126211 140537 INFO  puppetlabs.facter - executed with command line: --debug oscheck_codeblock oscheck_factervalue.
2018-08-17 13:
21 28 : 09 22 . 126619 140979 DEBUG leatherman.ruby:504 - ruby was found at "/usr/bin/ruby".
2018-08-17 13:
21 28 : 09 22 . 126762 141139 DEBUG leatherman.execution:93 - executing command: /usr/bin/ruby -e print(['libdir', 'archlibdir', 'sitearchlibdir', 'bindir'].find do |name|dir = RbConfig::CONFIG[name];next unless dir;file = File.join(dir, RbConfig::CONFIG['LIBRUBY_SO']);break file if File.exist? file;false end)
2018-08-17 13:
21 28 : 09 22 . 242077 295315 DEBUG | - /usr/lib/x86_64-linux-gnu/libruby-2.3.so.2.3.0
2018-08-17 13:
21 28 : 09 22 . 242280 295528 DEBUG leatherman.execution:559 - process exited with status code 0.
2018-08-17 13:
21 28 : 09 22 . 246717 299951 INFO  leatherman.ruby:137 - ruby loaded from "/usr/lib/x86_64-linux-gnu/libruby-2.3.so.2.3.0".
2018-08-17 13:
21 28 : 09 22 . 247314 300503 DEBUG leatherman.dynamic_library:77 - symbol rb_data_object_alloc not found in library /usr/lib/x86_64-linux-gnu/libruby-2.3.so.2.3.0, trying alias rb_data_object_wrap.
2018-08-17 13:
21 28 : 09 22 . 357056 418246 INFO  leatherman.ruby:186 - using ruby version 2.3.3
2018-08-17 13:
21 28 : 09 22 . 357220 418408 INFO  puppetlabs.facter - requested queries: oscheck_codeblock oscheck_factervalue.
2018-08-17 13:
21 28 : 09 22 . 357303 418488 DEBUG puppetlabs.facter - fact "facterversion" has resolved to "3.11.3".
2018-08-17 13:
21 28 : 09 22 . 357678 418857 DEBUG leatherman.file_util:65 - Error reading file: No such file or directory
2018-08-17 13:
21 28 : 09 22 . 358390 419635 DEBUG puppetlabs.facter - loading all custom facts.
2018-08-17 13:
21 28 : 09 22 . 358435 419683 DEBUG puppetlabs.facter - loading custom fact directories from config file
2018-08-17 13:
21 28 : 09 22 . 358494 419733 DEBUG puppetlabs.facter - searching for custom facts in /home/chrisb.
2018-08-17 13:
21 28 : 09 22 . 358649 419890 INFO  puppetlabs.facter - loading custom facts from /home/chrisb/ oscheck_codeblock.rb.
2018-08-17 13:21:09.358964 INFO  puppetlabs.facter - loading custom facts from /home/chrisb/
oscheck_factervalue.rb.
2018-08-17 13:
21 28 : 09 22 . 359177 420223 DEBUG puppetlabs.facter - searching for custom fact "os".
2018-08-17 13:
21 28 : 09 22 . 359250 420281 DEBUG puppetlabs.facter - searching for os.rb in /home/chrisb.
2018-08-17 13:
21 28 : 09 22 . 359343 420403 DEBUG puppetlabs.facter - resolving operating system facts.
2018-08-17 13:
21 28 : 09 22 . 359397 420506 DEBUG puppetlabs.facter - resolving kernel facts.
2018-08-17 13:
21 28 : 09 22 . 359472 420623 DEBUG puppetlabs.facter - fact "kernel" has resolved to "Linux".
2018-08-17 13:
21 28 : 09 22 . 359522 420711 DEBUG puppetlabs.facter - fact "kernelrelease" has resolved to "2.6.32-042stab123.9".
2018-08-17 13:
21 28 : 09 22 . 359644 420906 DEBUG puppetlabs.facter - fact "kernelmajversion" has resolved to "2.6".
2018-08-17 13:
21 28 : 09 22 . 359698 421009 DEBUG puppetlabs.facter - fact "kernelversion" has resolved to "2.6.32".
2018-08-17 13:
21 28 : 09 22 . 359783 421155 DEBUG leatherman.execution:93 - executing command: /usr/bin/lsb_release -a
2018-08-17 13:
21 28 : 09 22 . 443491 525733 DEBUG !!! - No LSB modules are available.
2018-08-17 13:
21 28 : 09 22 . 443611 525855 DEBUG | - Distributor ID: Debian
2018-08-17 13:
21 28 : 09 22 . 443689 525932 DEBUG | - Description: Debian GNU/Linux 9.5 (stretch)
2018-08-17 13:
21 28 : 09 22 . 443743 525987 DEBUG | - Release: 9.5
2018-08-17 13:
21 28 : 09 22 . 443795 526038 DEBUG | - Codename: stretch
2018-08-17 13:
21 28 : 09 22 . 452773 536786 DEBUG leatherman.execution:559 - process exited with status code 0.
2018-08-17 13:
21 28 : 09 22 . 455774 539651 DEBUG puppetlabs.facter - fact "osfamily" has resolved to "Debian".
2018-08-17 13:
21 28 : 09 22 . 455897 539761 DEBUG puppetlabs.facter - fact "operatingsystemmajrelease" has resolved to "9".
2018-08-17 13:
21 28 : 09 22 . 455983 539843 DEBUG puppetlabs.facter - fact "operatingsystemrelease" has resolved to "9.5".
2018-08-17 13:
21 28 : 09 22 . 456065 539919 DEBUG puppetlabs.facter - fact "hardwaremodel" has resolved to "x86_64".
2018-08-17 13:
21 28 : 09 22 . 456157 539994 DEBUG puppetlabs.facter - fact "architecture" has resolved to "amd64".
2018-08-17 13:
21 28 : 09 22 . 456237 540069 DEBUG puppetlabs.facter - fact "lsbdistid" has resolved to "Debian".
2018-08-17 13:
21 28 : 09 22 . 456320 540154 DEBUG puppetlabs.facter - fact "lsbdistcodename" has resolved to "stretch".
2018-08-17 13:
21 28 : 09 22 . 456404 540230 DEBUG puppetlabs.facter - fact "lsbdistdescription" has resolved to "Debian GNU/Linux 9.5 (stretch)".
2018-08-17 13:
21 28 : 09 22 . 456488 540310 DEBUG puppetlabs.facter - fact "lsbmajdistrelease" has resolved to "9".
2018-08-17 13:
21 28 : 09 22 . 456571 540387 DEBUG puppetlabs.facter - fact "lsbminordistrelease" has resolved to "5".
2018-08-17 13:
21 28 : 09 22 . 457114 540465 DEBUG puppetlabs.facter - fact "lsbdistrelease" has resolved to "9.5".
2018-08-17 13:
21 28 : 09 22 . 457338 540541 DEBUG puppetlabs.facter - fact "operatingsystem" has resolved to "Debian".
2018-08-17 13:
21 28 : 09 22 . 457598 540634 DEBUG puppetlabs.facter - fact "selinux" has resolved to false.
2018-08-17 13:
21 28 : 09 22 . 457773 540732 DEBUG puppetlabs.facter - fact "os" has resolved to {
  architecture => "amd64",
  distro => {
    codename => "stretch",
    description => "Debian GNU/Linux 9.5 (stretch)",
    id => "Debian",
    release => {
      full => "9.5",
      major => "9",
      minor => "5"
    }
  },
  family => "Debian",
  hardware => "x86_64",
  name => "Debian",
  release => {
    full => "9.5",
    major => "9",
    minor => "5"
  },
  selinux => {
    enabled => false
  }
}.
2018-08-17 13:
21 28 : 09 22 . 458213 ERROR puppetlabs.facter - error while resolving custom facts in /home/chrisb/oscheck_factervalue.rb: expected a String or Symbol for confine key
2018-08-17 13:21:09.458484
541146 DEBUG puppetlabs.facter - custom fact " oscheck_codeblock debian " resolved to null and will was not be added found .
2018-08-17 13:
21 28 : 09 22 . 458618 541242 DEBUG puppetlabs.facter - fact "oscheck_factervalue" resolved to null and will not be added.
2018-08-17 13:
21 28 : 09 22 . 458806 541403 DEBUG puppetlabs.facter - skipping external facts for "/home/chrisb/.puppetlabs/opt/facter/facts.d": No such file or directory
2018-08-17 13:
21 28 : 09 22 . 458901 541484 DEBUG puppetlabs.facter - skipping external facts for "/home/chrisb/.facter/facts.d": No such file or directory
2018-08-17 13:
21 28 : 09 22 . 458967 541537 DEBUG puppetlabs.facter - no external facts were found.
2018-08-17 13:
21 28 : 09 22 . 459110 541659 DEBUG puppetlabs.facter - fact " oscheck_codeblock" does not exist.
2018-08-17 13:21:09.459201 DEBUG puppetlabs.facter - fact "
oscheck_factervalue" does not exist.
oscheck_codeblock =>
oscheck_factervalue =>
{code}

Chris Butler (JIRA)

unread,
Aug 17, 2018, 8:41:03 AM8/17/18
to puppe...@googlegroups.com
Chris Butler commented on Bug FACT-1875
 
Re: Unable to use "confine" with structured facts -- documentation is incorrect

For anyone paying attention, I realised my error with the "code block" style confine check as soon as I pressed submit (typical!). However it still seems like the Facter.value method mentioned in the docs doesn't work, unless I'm also missing something there!

Scott McClellan (JIRA)

unread,
Aug 21, 2018, 4:43:03 PM8/21/18
to puppe...@googlegroups.com

Scott McClellan (JIRA)

unread,
Aug 21, 2018, 4:44:05 PM8/21/18
to puppe...@googlegroups.com

Daniel Kimsey (JIRA)

unread,
Aug 28, 2018, 11:26:04 AM8/28/18
to puppe...@googlegroups.com
Daniel Kimsey commented on Bug FACT-1875
 
Re: Unable to use "confine" with structured facts -- documentation is incorrect

For what it's worth I encountered this same issue on CentOS 7 with:

puppet-agent-1.10.14-1 (facter 3.6.10, puppet 4.10.12).

I was able to work-around the issue by using a block for confine (contrived example):

2018-08-28 10:23:49.006747 DEBUG puppetlabs.facter - fact "os" has resolved to {
  architecture => "x86_64",
  family => "RedHat",
  hardware => "x86_64",
  name => "CentOS",
  release => {
    full => "7.5.1804",
    major => "7",
    minor => "5"
  },
  selinux => {
    config_mode => "enforcing",
    config_policy => "targeted",
    current_mode => "enforcing",
    enabled => true,
    enforced => true,
    policy_version => "28"
  }
}. 

Facter.add(:my_fact) do
    confine :os do |os_hash|
        os_hash['release']['full'] == '7'
    end
    setcode do
       'fact value'
    end
end 

Garrett Guillotte (JIRA)

unread,
Aug 30, 2018, 7:42:02 PM8/30/18
to puppe...@googlegroups.com

William Rodriguez (JIRA)

unread,
Jan 19, 2019, 10:19:03 PM1/19/19
to puppe...@googlegroups.com

Thomas Kishel (Jira)

unread,
Mar 17, 2020, 2:27:03 PM3/17/20
to puppe...@googlegroups.com

Confirmed. With the move to eliminate legacy facts, this is important.

Facter.add('confine_test') do
  # Fails:
  # confine Facter.value(:os)['family'] => 'RedHat'
  # Succeeds:
  confine :os do |os|
    os['family'] == 'RedHat'
  end
  setcode do
    'success'
  end
end

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

Brian McNally (Jira)

unread,
Jun 16, 2022, 12:58:01 PM6/16/22
to puppe...@googlegroups.com

This is still a problem, but I can confirm that this style does seem to work:

 

confine :os do |os|
os['family'] == 'RedHat'
end

 

Please update the documentation to reflect that we can't use the Facter... syntax or fix this bug so that it works as the documentation states. Why has this not been addressed in 4 years?

This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo

Josh Cooper (Jira)

unread,
Dec 9, 2022, 4:52:02 PM12/9/22
to puppe...@googlegroups.com
Josh Cooper commented on Bug FACT-1875

What's really going on is the statement resolves the value of the structured fact and make it the key. So
 

confine Facter.value(:os)['distro']['id'] => 'Ubuntu' 

is resolved to the following when running on Ubuntu:

confine 'Ubuntu' => 'Ubuntu' 

Using the block form avoids that confusion. It also seems possible to us dotted notation (at least in Facter 4):

confine :'os.distro.id' => 'Ubuntu'

Having a lint check for this would be handy, cc Ben Ford, Craig Gumbley

This message was sent by Atlassian Jira (v8.20.11#820011-sha1:0629dd8)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages