Puppet not recieving hiera data

0 votes

I'm trying to use hiera and puppet together. I've added hiera_proxy yaml file in hiera hierarchy and am using it as the default hiera source file. For some reason, I'm not getting the hiera data value and it shows up this error.

Where, hiera_proxy is the new environment created

hierafile 1 /etc/puppetlabs/code/environments/hiera_proxy/hiera.yaml

version: 5
defaults:
  # The default value for "datadir" is "data" under the same directory as the hiera.yaml
  # file (this file)
  # When specifying a datadir, make sure the directory exists.
  # See https://docs.puppet.com/puppet/latest/environments.html for further details on environments.
  # datadir: data
  # data_hash: yaml_data


hierarchy:
  - name: "environment specific yaml"
    path: "hiera_proxy.yaml"
  - name: "Per-node data (yaml version)"
    path: "nodes/%{::trusted.certname}.yaml"
  - name: "Other YAML hierarchy levels"
    paths:
      - "common.yaml"

This is the hiera_proxy.yaml hiera data source file

This is the yaml hiera source named as hiera_proxy.yaml as in herarchy/etc/puppetlabs/code/environments/hiera_proxy/data/hiera-proxy.yaml

---
profiles::apache::servername: "taraserver.com"
profiles::apache::port: "80"
profiles::apache::docroot: "/var/www/tarahost"

hiera lookup in profile

$servername  = hiera('profiles::apache::servername',{})
  $port        = hiera('profiles::apache::port',{})
  $docroot     = hiera('profiles::apache::docroot',{})
  class profile::apache{
    #configure apache
    include apache
    apache::vhost{$servername:
      port    => $port,
      docroot => $docroot,
    }
  }

#ERROR:


Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: {"message":"Server Error: Evaluation Error: Error while evaluating a Resource Statement, Apache::Vhost[7fba80ae621c.domain.name]: parameter 'docroot' expects a value of type Boolean or String, got Undef at /etc/puppetlabs/code/environments/hiera_proxy/modules/profile/manifests/apache.pp:29 on node 94707b03ff05.domain.name","issue_kind":"RUNTIME_ERROR"}
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
May 7, 2018 in Other DevOps Questions by Damon Salvatore
• 5,490 points
200 views

1 answer to this question.

0 votes

Puppet does not consider the variables defined outside of the class. You need to define them inside the class.

your profile class should look something like this:

class profiles::apache (
  String $servername,
  Integer $port,
  String $docroot,
) {
  include apache
  apache::vhost { $servername:
    port    => $port,
    docroot => $docroot,
  }
}

I've used automatic parameter lookup to set up variables, instead of calling hiera function

answered May 7, 2018 by ajs3033
• 7,240 points

Related Questions In Other DevOps Questions

0 votes
1 answer

Execute puma workers only in prod but not in dev environment

You can us RACK_ENV here instead of ...READ MORE

answered Aug 16, 2018 in Other DevOps Questions by ajs3033
• 7,240 points
50 views
+13 votes
2 answers
0 votes
1 answer
+1 vote
2 answers

Unable to build TFS project because files not found

Please make a folder in solution Nd ...READ MORE

answered May 16 in Other DevOps Questions by Shashikesh Mishra
348 views
0 votes
1 answer

Command not working in .bat script but works in CLI

powershell /? If you run the above command ...READ MORE

answered Jul 19, 2018 in Other DevOps Questions by ajs3033
• 7,240 points
28 views
0 votes
1 answer
0 votes
1 answer

Not receiving any data from the BitStamp API.

I saw a code online that was ...READ MORE

answered Aug 21, 2018 in Blockchain by digger
• 27,620 points
42 views