Ask Your Question

Evaluation Error: Operator '[]' is not applicable to an Undef Value.

asked 2017-08-14 11:19:36 -0600

michaelokoluko gravatar image

What's the descriptive meaning of this error?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2017-08-16 05:05:49 -0600

fvoges gravatar image

You should share the full error message and code that trigger the error.

Without that information, that error probably means that you are treating an undefined variable (a variable that is not been set) as a hash or array , and when trying to access a key/member, it fails because undefined values have neither of those.

edit flag offensive delete link more

answered 2017-08-16 10:49:20 -0600

reesek gravatar image

If using facts to evaluate inside of a condition, you won't be able to access secondary elements if one isn't returned to the first element.

For example:

  # If false, include rhel::resolv
  unless $::facts['dhcp_servers']['system'] {
    include rhel::resolv

If this systems interface was not configured via DHCP, a puppet run would result in:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Operator '[]' is not applicable to an Undef Value. at /etc/puppetlabs/code/environments/snd/modules/rhel/manifests/init.pp:25:10 on node mongodb

This means that the facts['dhcp_servers'] is empty, which results in an undef value, as documented by Puppet:

whenever no other value is applicable, the value is undef

Thus, we cannot access the ['system'] element, just as the error suggests:

Operator '[]' is not applicable to an Undef Value.

Since the dhcp_server fact will result in an undef value provided the servers interface was not setup via DHCP, we can simply rely on it to satisfy our conditional which aims whether or not to include rhel::resolv.

edit flag offensive delete link more

answered 2017-08-16 06:55:49 -0600

greynolds gravatar image

To gain more insight run the --debug switch then capture the out put. If you want to move on without finding a solution you can try to set the variable assignment as a hash, "{}" In short, more information is needed.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools


Asked: 2017-08-14 11:19:36 -0600

Seen: 1,476 times

Last updated: Aug 16 '17