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,980 points
2,328 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,300 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,300 points
1,314 views
0 votes
1 answer

Azure DevOps yaml passing variable using "##vso[task.setvariable" not working

You can stop the pipeline from running ...READ MORE

answered Feb 8, 2022 in Other DevOps Questions by Bhavitha
• 1,000 points
1,845 views
0 votes
0 answers
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,036 views
+2 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 17, 2019 in Other DevOps Questions by Shashikesh Mishra
4,755 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,300 points
1,536 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP