Hiera价值无法以木偶轮廓接收

问题描述 投票:0回答:1
  1. 我创建了一个proxy_match.yaml文件作为默认hiera datalocation一个hiera源文件。
  2. 该proxy_match.yaml在hiera层次添加
  3. 仰望hiera轮廓数据

在哪里,我在想什么,我不能够接收hiera数据值,因此出现错误提到波纹管。

其中,proxy_match是创造了新的环境

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海尔数据源文件

这是命名为proxy_match.yaml在herarchy /etc/puppetlabs/code/environments/proxy_match/data/proxy-match.yaml的YAML hiera源

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

在外形hiera查找

$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,
    }
  }

#错误:


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
puppet hiera
1个回答
3
投票

您所定义的类定义之外的变量。当木偶加载一个类,类之前你有这些行会被忽略。

你应该在你的个人资料类:

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

请注意,我用的automatic parameter lookup功能,将您的变量,而不是显式调用到hiera功能。

© www.soinside.com 2019 - 2024. All rights reserved.