Ask Your Question
0

Handling Error 400 on Undef Gracefully

asked 2015-07-09 09:30:06 -0500

Antitribu gravatar image

updated 2015-07-09 10:40:14 -0500

We are receiving the following error:

Jul 9 15:16:12 server puppet-agent[10183]: Could not retrieve catalog from remote server: Error 400 on SERVER: $$jboss_hiera[$project][$application] is :undef, not a hash or array at /etc/puppet/environments/production/modules/jboss/manifests/applications/application.pp:39 on node server.local

The Hiera looks like:

jboss:
  urls:
    uri1: www.example.com/1
    uri2: www.example.com/2

  project1:
    version: 6.5
    app1:
      application_properties:
        val1: 1234
        val2: 5678

  project2:
    version: 6.5
    application_properties:
      foo: bar
      grr: hmm

The pp (line 39-41) file reads something like

  if $jboss_hiera[$project][$application]['application_properties'] != undef {
    $jboss_application_properties = $jboss_hiera[$project][$application]['application_properties']
  }

So the code is supposed to catch an undefined variable and handle this gracefully if it doesn't exist (as it may well not). However for values of project/application other than project1/app1 this does not happen. I've tried changing the hiera lookup default value to false with no luck.

Any suggestions?

Thanks

edit retag flag offensive close merge delete

Comments

Ended up working around using nested ifs in the template, so an exists for each level of the hash is checked before moving onto the next one,

Antitribu gravatar imageAntitribu ( 2015-07-09 10:41:00 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-07-11 04:08:34 -0500

The issue here is probably that the key $jboss_hiera[$project][$application] doesn't exist.

You probably want something like

if $jboss_hiera[$project] and
   $jboss_hiera[$project][$application] and
   $jboss_hiera[$project][$application]['application_properties']
{
  $jboss_application_properties = $jboss_hiera[$project][$application]['application_properties']
}
edit flag offensive delete link more

Comments

Thanks, looks like this is it. I ended up implementing this in the template however as multiple if's. If it is all as one if statement will it evaluate in order and not throw an error? Thanks

Antitribu gravatar imageAntitribu ( 2015-07-13 01:31:21 -0500 )edit

Yes that's right.

Alex Harvey gravatar imageAlex Harvey ( 2015-07-13 19:27:25 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-07-09 09:30:06 -0500

Seen: 112 times

Last updated: Jul 11 '15