Puppet Hiera 5查找功能值

时间:2017-03-23 02:39:39

标签: puppet hiera

我在我的系统中测试此博客文章的最后一个样本。我的查找命令给出不同的结果。我想明白为什么

https://www.devco.net/archives/2016/03/13/the-puppet-4-lookup-function.php

对于这个查找命令,他得到了这个值

% puppet lookup --environmentpath environments classifier::classes
---
- sysadmins
- nagios
- webserver

这是我的配置:

# cat /etc/puppetlabs/puppet/hiera.yaml
version: 5
defaults:
  datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata"
  data_hash: yaml_data
hierarchy:
   - name: "Other YAML hierarchy levels"
     paths:
        - "groups/%{facts.hostname}.yaml"
        - "os/%{facts.os.family}.yaml"
        - "common.yaml"

数据文件:

# cat "/etc/puppetlabs/code/environments/production/hieradata/groups/webserver.yaml"
classifier::classes:
  - nagios
  - --sensu
  - webserver

cat "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
---
version: 5

classifier::classes:
  - sensu
  - sysadmins

我的查找命令给出了这个值:

#  puppet lookup --environmentpath environments classifier::classes                                        ---
- nagios
- "--sensu"
- webserver

调试命令输出:

# puppet lookup --environmentpath environments --explain classifier::classes
Searching for "lookup_options"
  Global Data Provider (hiera configuration version 5)
    Using configuration "/etc/puppetlabs/puppet/hiera.yaml"
    Hierarchy entry "Other YAML hierarchy levels"
      Merge strategy hash
        Path "/etc/puppetlabs/code/environments/production/hieradata/groups/webserver.yaml"
          Original path: "groups/%{facts.hostname}.yaml"
          No such key: "lookup_options"
        Path "/etc/puppetlabs/code/environments/production/hieradata/os/RedHat.yaml"
          Original path: "os/%{facts.os.family}.yaml"
          Path not found
        Path "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
          Original path: "common.yaml"
          No such key: "lookup_options"
  Module "classifier" not found
Searching for "classifier::classes"
  Global Data Provider (hiera configuration version 5)
    Using configuration "/etc/puppetlabs/puppet/hiera.yaml"
    Hierarchy entry "Other YAML hierarchy levels"
      Path "/etc/puppetlabs/code/environments/production/hieradata/groups/webserver.yaml"
        Original path: "groups/%{facts.hostname}.yaml"
        Found key: "classifier::classes" value: [
          "nagios",
          "--sensu",
          "webserver"
        ]
  1. 为什么我得到不同的输出?
  2. 为什么我的调试命令没有给出“合并策略”消息?
  3. 由于 SR

    根据Matt的回复,我在common.yaml文件中添加了这个。

    # puppet lookup --environmentpath environments classifier::classes
    ---
    - sysadmins
    - nagios
    - webserver
    

1 个答案:

答案 0 :(得分:0)

RIPieenar与您所做的事情(查找/数据提供商版本,模块数据与环境数据等)之间存在一些差异,但输出差异的主要原因是缺少使用&# 34; deep_merge"在您的合并策略中。在您的puppetserver上安装deep_merge gem之后,您可以更改查找以使用该策略而不是hash

# /etc/puppetlabs/code/environments/production/hieradata/common.yaml
lookup_options:
  classifier::classes:
    merge:
      strategy: deep
      knockout_prefix: "--"
      unpack_arrays: ","
      sort_merge_arrays: true

这将为您提供与他在博客中发布的相同的输出。