I’m using the Ruby find command to collect the information I need from the Puppet Database as below.
vm_name = puppetdb.find { |details| details['certname']==(hostname) and details['name'] == 'az_metadata' }['value']['compute']['name']
Some of the parameters don’t have ‘az_metadata’ parameters, and that causes the find function to show “undefined method `[]' for nil: nil class (no method error).” How can I handle those or undefined method values from the find result for that specific variable?
How can I handle those or undefined method values from the find result for that specific variable?
From the error, it seems the value to a key in the results is
nil.You can use dig method or the Safe Navigation Operator