puppet-alternatives icon indicating copy to clipboard operation
puppet-alternatives copied to clipboard

Could not evaluate: undefined method `[]' for nil:NilClass

Open jhoblitt opened this issue 2 years ago • 7 comments

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: AIO 6 & 7
  • Distribution: Almalinux 9
  • Module version: 4.2.0

How to reproduce (e.g Puppet code you use)

        package { 'python3': }
        -> alternatives { 'python':
          path => '/usr/bin/python3',
        }

What are you seeing

The above code snippet works fine on EL8 under beaker but is producing an error on EL9.

Info: Applying configuration version '1675111504'
Debug: /Stage[main]/Main/Package[python3]/before: before to Alternatives[python]
Debug: Prefetching dnf resources for package
Debug: Executing: '/usr/bin/rpm --version'
Debug: Executing '/usr/bin/rpm -qa --nosignature --nodigest --qf '%{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\n' | sort'
Debug: Facter: resolving fact with user_query: osfamily
Debug: Facter: Searching fact: osfamily in file: osfamily.rb
Debug: Facter: Searching fact: osfamily in core facts and external facts
Debug: Facter: Loading all internal facts
Debug: Facter: List of resolvable facts: [#<Facter::SearchedFact:0x000000000428ce50 @name="osfamily", @fact_class=Facts::Rhel::Os::Family, @user_query="osfamily", @type=:legacy, @file=nil>]
Debug: Facter: Loading external facts
Debug: Facter: fact "osfamily" has resolved to: RedHat
Debug: Facter: resolving fact with user_query: osfamily
Debug: Facter: Searching fact: osfamily in file: osfamily.rb
Debug: Facter: Searching fact: osfamily in core facts and external facts
Debug: Facter: Loading all internal facts
Debug: Facter: List of resolvable facts: [#<Facter::SearchedFact:0x000000000421fe40 @name="osfamily", @fact_class=Facts::Rhel::Os::Family, @user_query="osfamily", @type=:legacy, @file=nil>]
Debug: Facter: Loading external facts
Debug: Facter: fact "osfamily" has resolved to: RedHat
Debug: Executing: '/usr/sbin/alternatives --display libnssckbi.so.x86_64'
Debug: Executing: '/usr/sbin/alternatives --display soelim'
Error: /Stage[main]/Main/Alternatives[python]: Could not evaluate: undefined method `[]' for nil:NilClass
/etc/puppetlabs/code/environments/production/modules/alternatives/lib/puppet/provider/alternatives/chkconfig.rb:53:in `path'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/property.rb:468:in `retrieve'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type.rb:1112:in `block in retrieve'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type.rb:1107:in `each'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type.rb:1107:in `retrieve'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type.rb:1130:in `retrieve_resource'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction/resource_harness.rb:307:in `from_resource'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction/resource_harness.rb:20:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:267:in `apply'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:288:in `eval_resource'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:191:in `call'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:191:in `block (2 levels) in evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:567:in `block in thinmark'
/opt/puppetlabs/puppet/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:566:in `thinmark'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:191:in `block in evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/graph/relationship_graph.rb:122:in `traverse'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:178:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/catalog.rb:238:in `block (2 levels) in apply'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:567:in `block in thinmark'
/opt/puppetlabs/puppet/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:566:in `thinmark'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/catalog.rb:237:in `block in apply'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/log.rb:165:in `with_destination'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction/report.rb:151:in `as_logging_destination'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/catalog.rb:236:in `apply'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/configurer.rb:286:in `block (2 levels) in apply_catalog'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:567:in `block in thinmark'
/opt/puppetlabs/puppet/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:566:in `thinmark'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/configurer.rb:285:in `block in apply_catalog'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:245:in `block in benchmark'
/opt/puppetlabs/puppet/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:244:in `benchmark'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/configurer.rb:284:in `apply_catalog'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/configurer.rb:500:in `run_internal'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/configurer.rb:339:in `run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application/apply.rb:361:in `apply_catalog'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application/apply.rb:273:in `block in main'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/context.rb:62:in `override'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb:289:in `override'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application/apply.rb:212:in `main'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application/apply.rb:182:in `run_command'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application.rb:421:in `block in run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:756:in `exit_on_fail'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application.rb:421:in `run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/command_line.rb:143:in `run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/command_line.rb:77:in `execute'
/opt/puppetlabs/puppet/bin/puppet:5:in `<main>'
Debug: Class[Main]: Resource is being skipped, unscheduling all events
Debug: Stage[main]: Resource is being skipped, unscheduling all events
Debug: Finishing transaction 12240
Debug: Storing state
Debug: Pruned old state cache entries in 0.00 seconds
Debug: Stored state in 0.01 seconds
Notice: Applied catalog in 0.10 seconds

jhoblitt avatar Jan 30 '23 20:01 jhoblitt

@bastelfreak @jsosic @vfoucault @treydock @alexjfisher @pseiler - It looks like you have all touched the chkconfig provider. Does anyone have an idea why self.class.all[name][:path] would be failing on EL9?

jhoblitt avatar Jan 30 '23 20:01 jhoblitt

Aww.

 ~ $ docker run -ti almalinux:8 alternatives --list
ld                  	auto  	/usr/bin/ld.bfd
libnssckbi.so.x86_64	auto  	/usr/lib64/pkcs11/p11-kit-trust.so
python              	auto  	/usr/libexec/no-python
 ~ $ docker run -ti almalinux:9 alternatives --list
ld                  	auto  	/usr/bin/ld.bfd
libnssckbi.so.x86_64	auto  	/usr/lib64/pkcs11/p11-kit-trust.so

jhoblitt avatar Jan 30 '23 20:01 jhoblitt

Still, it seems like the provider should fail with a more useful error message?

jhoblitt avatar Jan 30 '23 20:01 jhoblitt

That error message is a common problem and yeah makes it tough to debug. I remember it from https://github.com/puppetlabs/puppetlabs-docker/issues/749 too.

kenyon avatar Feb 01 '23 05:02 kenyon

I think this is because of all files in lib/puppet/provider/*/{chkconfig,dpkg}.rb.

Debian started a more modern implementation of (update-)alternatives. But chkconfig also provided an implementation. But it seems on RHEL9 basically RedHat also switched to the dpkg implementation. So we need to implement conditional statements into the *.rb files which I'm not able to do so at the moment. So starting with RHEL9 we should enable dpkg.rb instead of chkconfig.rb for RedHat systems. It's always in the first lines of code.

pseiler avatar Feb 01 '23 08:02 pseiler

I was able to get it working on EL9 with the chkconfig provider. The root cause of the breakage was that EL9 doesn't have a python alternative entry by default. This snippet got it to work:

      if versioncmp($facts['os']['release']['major'],'8') >= 0 {
        package { 'python3': }
        -> alternatives { 'python':
          path => '/usr/bin/python3',
        }
      }
      if versioncmp($facts['os']['release']['major'],'9') >= 0 {
        alternative_entry {'/usr/bin/python3':
          ensure   => present,
          altlink  => '/usr/bin/python',
          altname  => 'python',
          priority => 30,
        }
        -> Alternatives['python']
      }

However, I believe this is still a valid bug as the provider shouldn't be throwing a stack trace for what is probably a common mis-configuration.

jhoblitt avatar Feb 01 '23 13:02 jhoblitt

Constraining the dpkg provider to work on EL9 might be a little tricky, as EL9 doesn't include chkconfig in the base package set, it still has a package for it.

I suppose we could try to do it by version strings EL8:

[root@49a3153f2133 /]# /usr/sbin/alternatives --version
alternatives version 1.19.1

EL9:

[root@1df906319d3c /]# /usr/sbin/alternatives --version
alternatives version 1.20

However, the EL9 /usr/sbin/alternatives does not seem to have the --get-selections flag used in the dpkg provider.

jhoblitt avatar Feb 01 '23 14:02 jhoblitt