puppetlabs / puppet-lint

Check that your Puppet manifests conform to the style guide
https://puppetlabs.github.io/puppet-lint/
MIT License
23 stars 13 forks source link

Crash on NoMethodError: undefined method `[]' for nil:NilClass #126

Closed Spindyckx closed 1 year ago

Spindyckx commented 1 year ago

puppet-lint version: 4.0.0 ruby version: 3.0.5-p211 platform: x86_64-linux file path: common/kernel.pp file contents:

# Manage kernel settings
class vdab_oracle::common::kernel {
#
  # Set shared memory parameters from Hiera, or auto-tune them
  # Memory settings can be set either via this or via sysctl directly (sysctl takes priority)
  $mem = $vdab_oracle::oracledb::memory
  validate_hash($mem)

  # Auto-tuning is not always desirable so is off by default
  if has_key($mem, 'autotune') and $mem[autotune] == 'true' { # lint:ignore:quoted_booleans
    $autotune = true
  } else {
    $autotune = false
  }

  unless defined(Sysctl['kernel.shmall']) {
    if has_key($mem, 'shmall') and $mem[shmall] != '0' {
      sysctl { 'kernel.shmall': value => $mem[shmall] }
    } else {
      # RAM - 1GB / pagesize
      if $autotune and $facts['autotune_shm[shmall]'] {
        sysctl { 'kernel.shmall': value => $autotune_shm[shmall] }
      }
    }
  }

  unless defined(Sysctl['kernel.shmmax']) {
    if has_key($mem, 'shmmax') and $mem[shmmax] != '0' {
      sysctl { 'kernel.shmmax': value => $mem[shmmax] }
    } else {
      # RAM / 2 in bytes
      if $autotune and $facts['autotune_shm'][shmmax] != '0' {
        sysctl { 'kernel.shmmax': value => $facts['autotune_shm'][shmmax] }
      }
    }
  }

  unless defined(Sysctl['vm.nr_hugepages']) {
    # Set to 0 manually to turn off hugepages (autotune will not do this)
    if has_key($mem, 'hugepages') {
      sysctl { 'vm.nr_hugepages': value => $mem[hugepages] }
    } else {
      # Numer of hugepages needed to cover all shared memory segments
      if $autotune and $facts['autotune_shm'][hugepages] != '0' {
        sysctl { 'vm.nr_hugepages': value => $facts['autotune_shm'][hugepages] }
      }
    }
  }

  # Static defaults (again, can be overriden by sysctl)
  unless defined(Sysctl['fs.aio-max-nr']) {
    sysctl { 'fs.aio-max-nr': value => '1048576' }
  }
  unless defined(Sysctl['fs.file-max']) {
    sysctl { 'fs.file-max': value => '6815744' }
  }
  unless defined(Sysctl['fs.inotify.max_user_watches']) {
    sysctl { 'fs.inotify.max_user_watches': value => '65536' }
  }
  unless defined(Sysctl['kernel.msgmax']) {
    sysctl { 'kernel.msgmax': value => '65536' }
  }
  unless defined(Sysctl['kernel.msgmnb']) {
    sysctl { 'kernel.msgmnb': value => '65536' }
  }
  unless defined(Sysctl['kernel.panic_on_oops']) {
    sysctl { 'kernel.panic_on_oops': value => '1' }
  }
  unless defined(Sysctl['kernel.sem']) {
    sysctl { 'kernel.sem': value => "250\t32000\t100\t128" }
  }
  unless defined(Sysctl['kernel.shmmni']) {
    sysctl { 'kernel.shmmni': value => '4096' }
  }
  unless defined(Sysctl['net.core.rmem_default']) {
    sysctl { 'net.core.rmem_default': value => '262144' }
  }
  unless defined(Sysctl['net.core.rmem_max']) {
    sysctl { 'net.core.rmem_max': value => '4194304' }
  }
  unless defined(Sysctl['net.core.wmem_default']) {
    sysctl { 'net.core.wmem_default': value => '262144' }
  }
  unless defined(Sysctl['net.core.wmem_max']) {
    sysctl { 'net.core.wmem_max': value => '1048576' }
  }
  unless defined(Sysctl['net.ipv4.conf.all.promote_secondaries']) {
    sysctl { 'net.ipv4.conf.all.promote_secondaries': value => '1' }
  }
  unless defined(Sysctl['net.ipv4.conf.all.rp_filter']) {
    sysctl { 'net.ipv4.conf.all.rp_filter': value => '0' }
  }
  unless defined(Sysctl['net.ipv4.conf.default.promote_secondaries']) {
    sysctl { 'net.ipv4.conf.default.promote_secondaries': value => '1' }
  }
  unless defined(Sysctl['net.ipv4.icmp_echo_ignore_broadcasts']) {
    sysctl { 'net.ipv4.icmp_echo_ignore_broadcasts': value => '1' }
  }
  unless defined(Sysctl['net.ipv4.ip_local_port_range']) {
    sysctl { 'net.ipv4.ip_local_port_range': value => "9000\t65500" }
  }
  unless defined(Sysctl['net.ipv4.tcp_fin_timeout']) {
    sysctl { 'net.ipv4.tcp_fin_timeout': value => '30' }
  }
  unless defined(Sysctl['net.ipv4.tcp_keepalive_intvl']) {
    sysctl { 'net.ipv4.tcp_keepalive_intvl': value => '30' }
  }
  unless defined(Sysctl['net.ipv4.tcp_keepalive_probes']) {
    sysctl { 'net.ipv4.tcp_keepalive_probes': value => '5' }
  }
  unless defined(Sysctl['net.ipv4.tcp_keepalive_time']) {
    sysctl { 'net.ipv4.tcp_keepalive_time': value => '1800' }
  }
  unless defined(Sysctl['vm.hugetlb_shm_group']) {
    sysctl { 'vm.hugetlb_shm_group': value => '199' }
  }

  # Disable transparent hugepages, Oracle wants to manage hugepages directly
  exec { 'Disable transparent hugepages':
    command => '/bin/echo never > /sys/kernel/mm/transparent_hugepage/enabled',
    unless  => "/bin/grep -c \"[never]\" /sys/kernel/mm/transparent_hugepage/enabled 2>/dev/null",
  }

  exec { 'Disable transparent hugepage defrag':
    command => '/bin/echo never > /sys/kernel/mm/transparent_hugepage/defrag',
    unless  => "/bin/grep -c \"[never]\" /sys/kernel/mm/transparent_hugepage/defrag 2>/dev/null",
  }

  # See http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2053145
  # We can't use /etc/modprobe.d/vmware-pvscsi.conf because we boot off initrd, so we add the appropriate
      # options to /etc/default/grub instead.  This requires the server to be rebooted in order to become active.
      exec { 'increase-vmware-pvscsi-queue-depth':
        command => '/bin/sed -ie \'/^GRUB_CMDLINE_LINUX=.*/s/"$/ transparent_hugepage=never vmw_pvscsi.cmd_per_lun=254 vmw_pvscsi.ring_pages=32"/\' /etc/default/grub && /sbin/grub2-mkconfig > /boot/grub2/grub.cfg', #lint:ignore:140chars
        unless  => '/bin/grep -q vmw_pvscsi /boot/grub2/grub.cfg',
      }
    }

error:

NoMethodError: undefined method `[]' for nil:NilClass
/usr/lib/ruby/gems/3.0.0/gems/puppet-lint-4.0.0/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb:125:in `block in check'
/usr/lib/ruby/gems/3.0.0/gems/puppet-lint-4.0.0/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb:115:in `each'
/usr/lib/ruby/gems/3.0.0/gems/puppet-lint-4.0.0/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb:115:in `check'
/usr/lib/ruby/gems/3.0.0/gems/puppet-lint-4.0.0/lib/puppet-lint/checkplugin.rb:21:in `run'
/usr/lib/ruby/gems/3.0.0/gems/puppet-lint-4.0.0/lib/puppet-lint/checks.rb:61:in `block in run'
/usr/lib/ruby/gems/3.0.0/gems/puppet-lint-4.0.0/lib/puppet-lint/checks.rb:58:in `each'
/usr/lib/ruby/gems/3.0.0/gems/puppet-lint-4.0.0/lib/puppet-lint/checks.rb:58:in `run'
/usr/lib/ruby/gems/3.0.0/gems/puppet-lint-4.0.0/lib/puppet-lint.rb:226:in `run'
/usr/lib/ruby/gems/3.0.0/gems/puppet-lint-4.0.0/lib/puppet-lint/bin.rb:85:in `block in run'
/usr/lib/ruby/gems/3.0.0/gems/puppet-lint-4.0.0/lib/puppet-lint/bin.rb:80:in `each'
/usr/lib/ruby/gems/3.0.0/gems/puppet-lint-4.0.0/lib/puppet-lint/bin.rb:80:in `run'
/usr/lib/ruby/gems/3.0.0/gems/puppet-lint-4.0.0/bin/puppet-lint:7:in `<top (required)>'
/usr/bin/puppet-lint:25:in `load'
/usr/bin/puppet-lint:25:in `<main>'
Spindyckx commented 1 year ago

fixed, was an error with the facts syntax, fixing this fixed the issue. still weird lint crashes due to this issue