简体   繁体   English

使用lookup命令在puppet中的多个hiera文件中查找相同的键

[英]Lookup same keys in multiple hiera files in puppet using lookup command

I am trying to read a key present in multiple hiera files and merge the values. 我试图读取多个hiera文件中存在的键并合并值。 My hiera file contains: 我的hiera文件包含:

hierarchy:
  - name: "Per-env secrets"
    paths:
      - "puppet/hiera/dict-1.yaml"
      - "puppet/hiera/dict-2.yaml"

and My puppet script contains: 和我的木偶脚本包含:

lookup(dictionaries,Hash).each |String $keyDico, Hash $valueDico| {
  notify{"The value of dictionary is: ${keyDico}": }

The key 'dictionaries' is present in both dict-1.yaml and dict-2.yaml. dict-1.yaml和dict-2.yaml中都有关键的“词典”。 However, It always reads and prints the Key from the first matched hiera file. 但是,它始终从第一个匹配的hiera文件中读取并打印Key。
I tried changing 'Hash' in lookup function's argument to 'Unique' or 'Deep'. 我尝试将查找函数的参数中的'Hash'更改为'Unique'或'Deep'。 But it didn't work. 但它没有用。

Getting error: Error: Evaluation Error: Resource type not found: Deep and Error: Evaluation Error: Resource type not found: Unique 获取错误: Error: Evaluation Error: Resource type not found: DeepError: Evaluation Error: Resource type not found: Unique
Is there any way to achieve this? 有没有办法实现这个目标?

Thanks in advance. 提前致谢。

If you look at the docs for specifying merge behaviours ( ref ), you can see that you need to specify the optional third argument to lookup , and you are getting that error because "unique" is being interpreted as the data type. 如果查看用于指定合并行为( ref )的文档,您可以看到需要指定要lookup的可选第三个参数,并且您将获得该错误,因为“unique”被解释为数据类型。

Try either: 尝试:

lookup(dictionaries, Hash, 'unique')

or 要么

lookup(dictionaries, Hash, {'strategy' => 'unique'})

according to whichever you find more readable. 根据你发现的更具可读性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM