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 42 forks source link

NoMethodError in os_patching_fact_generation.sh #180

Closed sharumpe closed 3 years ago

sharumpe commented 4 years ago

Affected Puppet, Ruby, OS and module versions/distributions

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

sudo /usr/local/bin/os_patching_fact_generation.sh

What are you seeing

-e:1:in `block in <main>': undefined method `match' for nil:NilClass (NoMethodError)
        from -e:1:in `select'
        from -e:1:in `<main>'

What behaviour did you expect instead

error-free run, resulting in updated facts.

Output log

Any additional information you'd like to impart

I have been receiving error messages like in "What are you seeing" in system mail as a result of the cron job that updates the facts. Based on checking the code, there appear to be packages in the catalog for which r['parameters']['ensure'] is nil, and therefore the .match throws a NoMethodError exception.

I have fixed this locally by adding a rescue false to the condition throwing the exception, allowing the processing to continue on. This appears to yield expected results in my test cases with and without an actual pinned package in the catalog.

Code that appears to work is:

VERSION_LOCK_FROM_CATALOG=$(cat $CATALOG | /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.+/) rescue false) }.each do | m | puts m['title'] end")

I will try to do a pull request shortly. I'm not a ruby programmer so hopefully that doesn't introduce other problems. :)

maxadamo commented 4 years ago

@albatrossflavour any plan to release 0.14 on forge?

TJM commented 3 years ago

@albatrossflavour PLEASE release v0.14.x with this fix! :) I have my entire team growling at me now. I had to downgrade back to v0.11, but it wasn't fast enough apparently several hundred systems got the 0.13.x update with the bad script. yikes!

albatrossflavour commented 3 years ago

I'm on it, sorry guys

albatrossflavour commented 3 years ago
image
maxadamo commented 3 years ago

Thanks @albatrossflavour ! Anyway, in metadata.json, you state that this module works with Puppet 7, but this is true only if you merge https://github.com/albatrossflavour/puppet_os_patching/pull/191 Right now, it fails on puppet 7.