Jira (PUP-11545) Evaluation Error: Error while evaluating a Function Call, undefined method `length' for nil:NilClass

205 views
Skip to first unread message

Manuel Lora Roman (Jira)

unread,
Jun 1, 2022, 5:52:03 AM6/1/22
to puppe...@googlegroups.com
Manuel Lora Roman created an issue
 
Puppet / Bug PUP-11545
Evaluation Error: Error while evaluating a Function Call, undefined method `length' for nil:NilClass
Issue Type: Bug Bug
Affects Versions: PUP 6.26.0
Assignee: Henrik Lindberg
Components: Functions, Modules
Created: 2022/06/01 2:51 AM
Labels: puppet puppet-agent centos7
Priority: Major Major
Reporter: Manuel Lora Roman

Puppet Version: puppet-agent-6.26
Puppet Server Version: puppetserver-6.18
OS Name/Version: CentOS 7

After executing the command of puppet agent -t we get the following error:

Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, undefined method `length' for nil:NilClass (file: /etc/puppetlabs/code/modules/yum/manifests/init.pp, line: 202, column: 20) on node XXX
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

 

We change the configuration of the init.pp with a solution that we encounter somewhere, and was to change this code:

 

$_pc_cmd = delete_undef_values([
    '/usr/bin/package-cleanup',
    '--oldkernels',
    "--count=${_real_installonly_limit}",
    '-y',
    $keep_kernel_devel ? {
      true    => '--keepdevel',
      default => undef,
    },
  ]) 

 

to this other one:

 

$_pc_cmd = [
    '/usr/bin/package-cleanup',
    '--oldkernels',
    "--count=${_real_installonly_limit}",
    '-y',
    $keep_kernel_devel ? {
      true    => '--keepdevel',
      default => undef,
    },
  ].filter |$val| { $val =~ NotUndef } 

 

There is a way of solving this issue whithout making any changes on the code?

 

Desired Behavior: No puppet errors

Actual Behavior: Execution getting errors

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

Josh Cooper (Jira)

unread,
Jun 1, 2022, 11:56:03 AM6/1/22
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Jun 1, 2022, 12:04:02 PM6/1/22
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-11545
 
Re: Evaluation Error: Error while evaluating a Function Call, undefined method `length' for nil:NilClass

Lorita this looks to be an error with your delete_undef_values function. Can you include your init.pp? Also it's possible to conditionally append elements to an array so you don't have to filter them out later:

$ puppet apply -e '$arr = [1, 2] << 3; notice($arr)'
Notice: Scope(Class[main]): [1, 2, 3]

Manuel Lora Roman (Jira)

unread,
Jun 2, 2022, 2:10:04 AM6/2/22
to puppe...@googlegroups.com

Hi,

 

My init.pp is the following:

class yum (
  Boolean $clean_old_kernels = true,
  Boolean $keep_kernel_devel = false,
  Hash[String, Variant[String, Integer, Boolean, Hash[String, Variant[String, Integer, Boolean]]]] $config_options = { },
  Optional[Hash[String, Optional[Hash[String, Variant[String, Integer, Boolean]]]]] $repos = {},
  Array[String] $managed_repos = [],
  Boolean $manage_os_default_repos = false,
  Array[String] $os_default_repos = [],
  Array[String] $repo_exclusions = [],
) {  $module_metadata            = load_module_metadata($module_name)
  $supported_operatingsystems = $module_metadata['operatingsystem_support']
  $supported_os_names         = $supported_operatingsystems.map |$os| {
    $os['operatingsystem']
  }  unless member($supported_os_names, $::os['name']) {
    fail("${::os['name']} not supported")
  }  $_managed_repos = $manage_os_default_repos ? {
    true    => $managed_repos + $os_default_repos,
    default => $managed_repos,
  }  unless empty($_managed_repos) or empty($repos) {
    $_managed_repos_minus_exclusions = $_managed_repos - $repo_exclusions
    $normalized_repos = yum::bool2num_hash_recursive($repos)    $normalized_repos.each |$yumrepo, $attributes| {
      if member($_managed_repos_minus_exclusions, $yumrepo) {
        Resource['yumrepo'] {
          $yumrepo: * => $attributes,
        }
      }
    }
  }  unless empty($config_options) {
    if has_key($config_options, 'installonly_limit') {
      assert_type(Variant[Integer, Hash[String, Integer]], $config_options['installonly_limit']) |$expected, $actual| {
        fail("The value or ensure for `\$yum::config_options[installonly_limit]` must be an Integer, but it is not.")
      }
    }    $_normalized_config_options = $config_options.map |$key, $attrs| {
      $_ensure = $attrs ? {
        Hash    => $attrs[ensure],
        default => $attrs,
      }      $_normalized_ensure = $_ensure ? {
        Boolean => Hash({ ensure => bool2num($_ensure) }), # lint:ignore:unquoted_string_in_selector
        default => Hash({ ensure => $_ensure }), # lint:ignore:unquoted_string_in_selector
      }      $_normalized_attrs = $attrs ? {
        Hash    => merge($attrs, $_normalized_ensure),
        default => $_normalized_ensure,
      }      Hash({ $key => $_normalized_attrs })
    }.reduce |$memo, $cfg_opt_hash| {
      merge($memo, $cfg_opt_hash)
    }    $_normalized_config_options.each |$config, $attributes| {
      Resource['yum::config'] {
        $config: * => $attributes,
      }
    }
  }  unless defined(Yum::Config['installonly_limit']) {
    yum::config { 'installonly_limit': ensure => '3' }
  }  $_clean_old_kernels_subscribe = $clean_old_kernels ? {
    true    => Yum::Config['installonly_limit'],
    default => undef,
  }  # cleanup old kernels
  ensure_packages(['yum-utils'])  $_real_installonly_limit = $config_options['installonly_limit'] ? {
    Variant[String, Integer] => $config_options['installonly_limit'],
    Hash                     => $config_options['installonly_limit']['ensure'],
    default                  => '3',
  }  $_pc_cmd = [
    '/usr/bin/package-cleanup',
    '--oldkernels',
    "--count=${_real_installonly_limit}",
    '-y',
    $keep_kernel_devel ? {
      true    => '--keepdevel',
      default => undef,
    },
  ].filter |$val| { $val =~ NotUndef }  
  exec { 'package-cleanup_oldkernels':
    command     => shellquote($_pc_cmd),
    refreshonly => true,
    require     => Package['yum-utils'],
    subscribe   => $_clean_old_kernels_subscribe,
  }
} 

Sorry for the identation in advance.

Thanks & regards.

Nirupama Mantha (Jira)

unread,
Jun 7, 2022, 4:24:02 PM6/7/22
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages