代码之家  ›  专栏  ›  技术社区  ›  Tara Prasad Gurung

无法在puppet配置文件中接收Hiera值

  •  0
  • Tara Prasad Gurung  · 技术社区  · 7 年前
    1. 默认hiera数据位置。

    2. proxy\u匹配。yaml添加到hiera层次结构中

    3. 在配置文件中查找hiera数据

    我在哪里遗漏了什么,我无法接收hiera数据 值,因此出现以下错误。

    哪里

    层次文件1 /etc/puppetlabs/code/environments/proxy\u match/hiera。亚马尔

    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\u匹配。yaml hiera数据源文件

    这是名为proxy\u match的yaml hiera源。亚马尔与赫拉希一样 /etc/puppetlabs/code/environments/proxy\u match/data/proxy match。亚马尔

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

    $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
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   Alex Harvey    7 年前

    您正在定义类定义之外的变量。当Puppet加载该类时,将忽略该类之前的那些行。

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

    注意,我使用了 automatic parameter lookup