Ask Your Question
0

module data hiera: Function lookup() did not find a value for the name

asked 2017-03-23 05:47:16 -0500

rssh22 gravatar image

updated 2017-03-23 06:35:22 -0500

Given a module like:

mymodule/
|-- data
|   `-- data.yaml
|-- hiera.yaml
|-- manifests
|   `-- init.pp
`-- metadata.json

mymodule/hiera.yaml
---
version: 4
datadir: data
#data_hash: yaml_data
hierarchy:
  - name: "data"
    backend: yaml
    path: "data/data.yaml"
  - name: "common"
    backend: yaml
mymodule/manifests/init.pp
    class mymodule {
      $var = lookup('mymodule::var')
      notify {"var: ${var}":}
    }
mymodule/data/data.yaml
    ---
    mymodule::var: 'var value from mymodule/data/data.yaml'
    mymodule/metadata.json
{
      "name": "example-mymodule",
      "version": "0.0.1",
      "author": "Pat",
      "license": "Apache-2.0",
      "summary": "A module for a thing",
      "source": "https://github.com/examplecorp/examplecorp-mymodule",
      "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
      "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
      "tags": ["things", "stuff"],
      "operatingsystem_support": [
        {
        "operatingsystem":"RedHat",
        "operatingsystemrelease":[ "5.0", "6.0" ]
        },
        {
        "operatingsystem": "Ubuntu",
        "operatingsystemrelease": [ "12.04", "10.04" ]
        }
       ],
      "dependencies": [
        { "name": "puppetlabs/stdlib", "version_requirement": ">= 3.2.0 < 5.0.0" }
      ],
      "data_provider": "hiera"
}

root@puppet-pil00:/etc/puppetlabs#  /opt/puppetlabs/bin/puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Function lookup() did not find a value for the name 'mymodule::var' on node puppet-pil00.msc.es
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

why lookup() can't find mymodule::var variable in data.yaml?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-03-24 13:44:02 -0500

Red Cricket gravatar image

updated 2017-03-24 22:45:39 -0500

According the the puppet style guide :

You should avoid using calls to Hiera functions in modules meant for public consumption, because not all users have implemented Hiera. Instead, we recommend using parameters that can be overridden with Hiera.

You can avoid calling lookup() by making var a class parameter. So you puppet class would look like this:

class mymodule (
      $var,
) {
      notify {"var: ${var}":}
}

Also I am not sure your hiera.yaml is correct. Have you tried just using the default hiera.yaml a just adding the line for your data yaml file? You should double check you hiera set up by running hiera from the command line on your puppet master with debug. Something like.

hiera --debug var environment=production

And see if the yaml files you assume are being searched are actually being read.

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

1 follower

Stats

Asked: 2017-03-23 05:47:16 -0500

Seen: 181 times

Last updated: Mar 24