Tara Prasad Gurung
Tara Prasad Gurung

Reputation: 3559

Hiera value not able to receiving in puppet profile

  1. I have created a proxy_match.yaml file as a hiera source file in default hiera datalocation.

  2. The proxy_match.yaml is added in hiera hierarchy

  3. Looking up hiera data in profile

Where and what am I missing, I am not able to receive the hiera data value and thus the error appears mentioned bellow.

Where, proxy_match is the new environment created

hierafile 1 /etc/puppetlabs/code/environments/proxy_match/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: "proxy_match.yaml"
  - name: "Per-node data (yaml version)"
    path: "nodes/%{::trusted.certname}.yaml"
  - name: "Other YAML hierarchy levels"
    paths:
      - "common.yaml"

proxy_match.yaml hiera data source file

This is the yaml hiera source named as proxy_match.yaml as in herarchy /etc/puppetlabs/code/environments/proxy_match/data/proxy-match.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/proxy_match/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

Upvotes: 0

Views: 1686

Answers (1)

Alex Harvey
Alex Harvey

Reputation: 15472

You are defining the variables outside the class definition. When Puppet loads that class, those lines you have before the class are ignored.

What you should have in your profile class is:

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

Note that I used the automatic parameter lookup feature to set your variables, instead of explicit calls to the hiera function.

Upvotes: 3

Related Questions