0
votes

I have a puppet question. (I'm using 5.1.0 version)

In this path: C:\ProgramData\PuppetLabs\code\environments\production\manifests I have the file: site.pp This file (/etc/puppetlabs/puppet/manifests/site.pp) is the main entry point used when an agent connects to a master and asks for an updated configuration.

This is the content of the file now:

node default {
  # This is where you can declare classes for all nodes.
  # Example:
  #   class { 'my_class': }
  #hiera_include('classes')
  include(hiera_array("classes", ))
}

But when I run the puppet with the puppet apply command which is:

"C:\Program Files\Puppet Labs\Puppet\bin\puppet" apply C:\ProgramData\PuppetLabs\code\environments\production\manifests\site.pp

I get this error:

Warning: The function 'hiera_array' is deprecated in favor of using 'lookup'. See https://docs.puppet.com/puppet/5.1/referenc
e/deprecated_language.html
   (file & line not available)
Error: Function lookup() did not find a value for the name 'classes'

So I changed the site.pp code into:

node default {
  # This is where you can declare classes for all nodes.
  # Example:
  #   class { 'my_class': }
  #hiera_include('classes')
  include(lookup('classes', {merge => unique}, ))
}

(because I found this doc: https://puppet.com/docs/puppet/5.1/hiera_migrate_functions.html)

And now I get only this error:

Error: Function lookup() did not find a value for the name 'classes'

I'm not sure how to fix it, because this code worked a month ago with the same apply command.

Can you please help me?

Thanks!

1
That lookup code should be lookup('classes', Array[String], 'unique').include. That will not completely fix your problem though, as it stems from a problem with your Hiera config and data organization which you have not given information about.Matt Schuchard
@MattSchuchard, the OP's call to lookup() is fine, as indeed the error message he (still) receives supports. The function has multiple alternative signatures, and the OP's use matches one of them.John Bollinger
@JohnBollinger I probably was unclear. I did not mean to imply that it was causing the error, but rather that it was sub-optimal regarding clarity, type-checking, etc. I still maintain my claim about the source of the error being from the hiera config/data organization. The question needs more info about that.Matt Schuchard

1 Answers

2
votes

I get this error:

Warning: The function 'hiera_array' is deprecated in favor of using 'lookup'. See https://docs.puppet.com/puppet/5.1/referenc e/deprecated_language.html (file & line not available)
Error: Function lookup() did not find a value for the name 'classes'

Correction: you get a warning and an error. The error is separate, but shows that Puppet is handling the situation it warned about by delegating to the new lookup() function internally.

So I changed the site.pp code into:

node default {
  # This is where you can declare classes for all nodes.
  # Example:
  #   class { 'my_class': }
  #hiera_include('classes')
  include(lookup('classes', {merge => unique}, ))
}

Yes, that is a perfectly good and natural way to resolve the warning, and it looks like it was successful at that. But again, the error is separate. It's not about your manifest, but rather about your data. As it says, the attempt to look up the key 'classes' failed. No such key was found. You did not supply lookup() with a default value to return in that case, so an error occurs.

I'm not sure how to fix it, because this code worked a month ago with the same apply command.

If Puppet once ran the same code without emitting an error, then what has changed between then and now is the data. Possibly, however, that was because you are now running Puppet as a different user. Different ordinary users all have their own default location for data (and manifests), and these all differ from the locations used when Puppet is run by the system.