Reese Knowledgebase

Various Puppet Errors

View Kristian Reese's profile on LinkedIn

If you like this article, please +1 or Recommend via FB with the provided buttons above:

Article ID: 173
by: Reese K.
Posted: 24 Jan, 2017
Last updated: 24 Jan, 2017
Views: 1298

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

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.

  # 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.

This article was:   Helpful | Not Helpful
Prev   Next
Could not request certificate     SUN