albatrossflavour / puppet_os_patching

A Puppet module that provides a set of tasks and custom facts which allows the automation of and reporting on OS patching
Apache License 2.0
44 stars 40 forks source link

os_patching_fact_generation.sh Script runs in nil:NilClass (NoMethodError) #226

Closed epgkue closed 1 year ago

epgkue commented 1 year ago

Affected Puppet, Ruby, OS and module versions/distributions

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

  1. Assign os_patching class to host
  2. Run puppet agent
  3. Running bash in debug script locally: bash -x /usr/local/bin/os_patching_fact_generation.sh

What are you seeing

.... ++ /opt/puppetlabs/puppet/bin/ruby -e 'require '\''json'\''; json_hash = JSON.parse(ARGF.read); json_hash['\''resources'\''].select { |r| r['\''type'\''] == '\''Package'\'' and r['\''parameters'\'']['\''ensure'\''].match /\d.+/ }.each do | m | puts m['\''title'\''] end' Traceback (most recent call last): 2: from -e:1:in <main>' 1: from -e:1:inselect' -e:1:in block in <main>': undefined methodmatch' for nil:NilClass (NoMethodError) ....

What behaviour did you expect instead

Updating os_patching facts to the Hosts to Foreman.

Any additional information you'd like to impart

albatrossflavour commented 1 year ago

I've not tested os_patching on alma yet, but sounds like that could be the culprit. We've also seen some issues using open source puppet with os_patching (I was designed to work with PE). I'll try and run up a test environment and see what I can find.

albatrossflavour commented 1 year ago

I've not been able to replicate this: CleanShot 2023-07-11 at 21 33 17

I've tried a few different combos, but no issues.

I did the following with a bare Alma instance:

rpm -Uvh https://yum.puppet.com/puppet7-release-el-8.noarch.rpm
yum install puppet-agent
puppet module install albatrossflavour/os_patching
puppet apply -e 'include os_patching'
bash -x /usr/local/bin/os_patching_fact_generation.sh

Did I miss anything?

albatrossflavour commented 1 year ago

@epgkue do you have any other steps I can try to reproduce this?

dirkonet commented 1 year ago

At least on my CentOS 7 machines, this seems to be the same issue as seen in #202 - one of my packages does not have an "ensure" parameter in the catalog, causing the array access to fail.

While this was fixed with #203, the patch seems to have been overwritten and is not in the current development branch or release. I'd suggest to re-apply #203.

albatrossflavour commented 1 year ago

Well spotted @dirkonet . I've applied the fix to development and will release an update soon.