簡體   English   中英

Puppet Hiera 5查找功能值

[英]Puppet Hiera 5 Lookup function value

我正在系統中測試此博客文章的最后一個示例。 我的查找命令給出了不同的結果。 我喜歡理解為什么

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. 為什么我的調試命令沒有給出“合並策略”消息?

謝謝SR


根據馬特的回應,我已經在我的common.yaml文件中添加了它。

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

RIPieenar和您所做的工作之間存在一些差異(查找/數據提供程序版本,模塊數據與環境數據等),但是造成輸出差異的主要原因是您的輸出中缺少使用“ deep_merge”合並策略。 deep_merge上安裝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

這將為您提供與他在博客中發布的輸出相同的輸出。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM