首页 > 解决方案 > Puppet 查找找不到层次键值

问题描述

我在我的 puppet 查找调用中看到了这个错误(使用 hiera 的基本测试):

puppet lookup --explain foo

Searching for "lookup_options"
  Global Data Provider (hiera configuration version 5)
    No such key: "lookup_options"
Searching for "foo"
  Global Data Provider (hiera configuration version 5)
    No such key: "foo"
Function lookup() did not find a value for the name 'foo'

尝试直接分层查找有效:

hiera -d foo
DEBUG: 2019-01-16 11:53:39 +0000: Hiera YAML backend starting
DEBUG: 2019-01-16 11:53:39 +0000: Looking up foo in YAML backend
DEBUG: 2019-01-16 11:53:39 +0000: Looking for data source common
DEBUG: 2019-01-16 11:53:39 +0000: Found foo in common
bar

我的 hiera.yaml 文件(位于 /etc):

---
version: 5
hierarchy:
  - name: Common
    path: common.yaml
defaults:
  data_hash: yaml_data
  datadir: data

我的 common.yaml 文件(位于 /var/lib/hiera):

---
foo: bar

谁能解释为什么我会看到这个错误(对 Puppet 来说相当新)...

标签: puppethiera

解决方案


这是一个文件位置问题。

我有:

▶ cat spec/fixtures/hiera/hiera.yaml 
---
version: 5
hierarchy:
  - name: Common
    path: common.yaml
defaults:
  data_hash: yaml_data
  datadir: data

结构:

▶ tree spec/fixtures/hiera
spec/fixtures/hiera
├── data
│   └── common.yaml
└── hiera.yaml

命令行:

▶ puppet lookup --hiera_config=spec/fixtures/hiera/hiera.yaml foo 
--- bar

请注意,在中引用的目录data必须相对于您所在的目录。参考hiera.yamldefaults.datadirhiera.yaml

datadir — 保存数据文件的目录;如果您设置默认值,则可以省略。

此路径相对于 hiera.yaml 的目录:如果配置文件位于 /etc/puppetlabs/code/environments/production/hiera.yaml 并且 datadir 设置为 data,则数据目录的完整路径为 /etc/puppetlabs /代码/环境/生产/数据。

在全局层中,您可以选择将 datadir 设置为绝对路径;在其他层中,它必须始终是相对的。


推荐阅读