【问题标题】:Puppet hiera not inheriting properly (Puppet version 4.3.2)Puppet hiera 没有正确继承(Puppet 版本 4.3.2)
【发布时间】:2016-06-06 11:48:08
【问题描述】:

我的/etc/puppetlabs/code 文件夹结构:

[vagrant@client code]$ pwd
/etc/puppetlabs/code
[vagrant@client code]$ tree
.
├── environments
│   ├── production
│   │   ├── environment.conf
│   │   ├── hieradata
│   │   ├── manifests
│   │   └── modules
│   └── test
│       ├── hieradata
│       ├── manifests
│       │   └── site.pp
│       └── modules
├── hieradata
│   ├── common.yaml
│   └── hostname
│       └── client.yaml
├── hiera.yaml
└── modules

然后,对于我的 YAML 文件:

[vagrant@client code]$ cat hiera.yaml 
---
:backends:
  - yaml
:hierarchy:
  - "hostname/%{facts.hostname}"
  - "os/%{facts.osfamily}"
  - common
:yaml:
  :datadir: /etc/puppetlabs/code/hieradata
merge_behavior: deeper

[vagrant@client code]$ cat hieradata/common.yaml 
---
users:
  jill:
    uid: 1000
    home: '/home/jill'
  jack:
    uid: 1001
    home: '/home/jack'

[vagrant@client code]$ cat hieradata/hostname/client.yaml 
---
users:
  jill:
    home: '/homes/jill'
  jack:
    home: '/homes/jack'
  jane:
    uid : 999
    home: '/homes/jane'

然而,当我运行 hiera 时,我得到以下信息:

[vagrant@client code]$ hiera --hash users
{"jill"=>{"uid"=>1000, "home"=>"/home/jill"},
 "jack"=>{"uid"=>1001, "home"=>"/home/jack"}}
[vagrant@client code]$ hiera --hash users ::hostname=client
{"jill"=>{"uid"=>1000, "home"=>"/home/jill"},
 "jack"=>{"uid"=>1001, "home"=>"/home/jack"}}

我的hieradata/hostname/client.yaml 应该覆盖common.yaml,导致hiera 命令在提交::hostname=client 时返回不同的内容。

我做错了什么?

【问题讨论】:

    标签: yaml puppet hierarchy hiera facter


    【解决方案1】:

    $facts 哈希是由 puppet 代理/应用设置的,当您尝试通过 hiera 命令行验证您的设置时,我不希望它可用。

    您可以在层次结构中使用 - "hostname/%{::hostname}" 从 hiera cmd 获取预期结果,或者考虑使用 puppet 命令行来验证您的设置。

    【讨论】:

    • 嗯,这部分有效,但不完全有效。它确实继承,但例如 uid=1000 不会传播给“客户”[vagrant@client code]$ hiera --hash users ::hostname=client {"jill"=>{"home"=>"/homes/jill"}, "jack"=>{"home"=>"/homes/jack"}, "jane"=>{"uid"=>999, "home"=>"/homes/jane"}} [vagrant@client code]$ hiera --hash users {"jill"=>{"uid"=>1000, "home"=>"/home/jill"}, "jack"=>{"uid"=>1001, "home"=>"/home/jack"}}
    • 啊,是的!在 merge_behaviour 之前缺少一个冒号。应该是:merge_behavior: deeper
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多