Ask Your Question
0

Hiera: How can I tell which class triggered 'expected Array and got NilClass'?

asked 2014-06-27 19:27:49 -0500

updated 2014-07-01 18:33:58 -0500

My Puppet agent is complaining about 'expected Array and got NilClass':

[root@clone1 ~]# puppet agent --test
...
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Hiera type mismatch: expected Array and got NilClass
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

I checked the logs on my Puppet Master and they say:

[root@puppet3 ~]# tail /var/log/messages
Jun 27 20:16:01 puppet3 puppet-master[32853]: Hiera type mismatch: expected Array and got NilClass
Jun 27 20:18:57 puppet3 puppet-master[32853]: Hiera type mismatch: expected Array and got NilClass
Jun 27 20:20:29 puppet3 puppet-master[32853]: Hiera type mismatch: expected Array and got NilClass

How can I tell what class triggered this error, short of poking through every single file in my datadir?

Update

For the record, this happened when I was following the example at "Hiera Complete Example". I added classes: to a YAML file, but failed to include any classes.

This caused the error:

[root@puppet3 puppet]# cat /etc/puppet/hieradata/osfamily/RedHat.yaml
---
classes:

vmwaretools::working_dir: /opt/vmware

I can fix it either by commenting out classes: or by adding a class to classes:. Since I'm testing, I'll comment it out for now.

[root@puppet3 puppet]# cat /etc/puppet/hieradata/osfamily/RedHat.yaml
---
#classes:

vmwaretools::working_dir: /opt/vmware
edit retag flag offensive close merge delete

Comments

give `puppet agent -t --debug` a shot

ptierno gravatar imageptierno ( 2014-06-28 09:27:52 -0500 )edit

@ptierno Unfortunately, `puppet agent -t --debug` returns nothing useful except for the error.

stefanlasiewski gravatar imagestefanlasiewski ( 2014-07-01 18:31:56 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-06-28 10:25:43 -0500

llowder gravatar image

updated 2014-07-02 07:17:43 -0500

Unfortunately, there is not a great way to do this.

What it looks like is you have an hiera_array() call and the key you are looking up was not found.

The Debugging Hiera blog has a lot of good info in how you can use the command line to help track down the problem, but the short version is something like the following.

for y in $(for x in $(puppet config print modulepath | sed -e "s/:/ /g"); do grep -PIRho "(?<=hiera_array\(['|\"|$])([^'|^\"|^,|^\)]+)" $x; done); do echo hiera  -d -a -c $(puppet config print confdir)/hiera.yaml $y <key=value pairs as needed for your hiera.yaml>; done

This is a (tested) nested for loop that will search your module path for all key values used in a hiera_array lookup, and then will perform the equivalent of a hiera_array() from puppet. You will likely need to set one or more key=value items to cover variables used in your hiera.yaml.

edit flag offensive delete link more

Comments

In an attempt to understand your code, I fleshed it out a bit. Try it out. Here's my code on Gist: https://gist.github.com/stefanlasiewski/160d534e9cf4af3d3831

stefanlasiewski gravatar imagestefanlasiewski ( 2014-07-01 19:09:52 -0500 )edit

I just noticed that the grep actually found `hiera()` calls not `hiera_array()`, so I fixed that. Also, the gist is giving a 404 - is it set private? I've got a more involved script that is almost ready or github that will do the above search, but better & more info.

llowder gravatar imagellowder ( 2014-07-02 07:19:46 -0500 )edit

Oh noes! The ask.puppetlabs.com software is inserting a HTML end-of-paragraph cahracter at the end of the link. Here it is again: https://gist.github.com/stefanlasiewski/160d534e9cf4af3d3831 (this is just padding to avoid the character)

stefanlasiewski gravatar imagestefanlasiewski ( 2014-07-02 12:05:04 -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: 2014-06-27 19:27:49 -0500

Seen: 2,088 times

Last updated: Jul 02 '14