我的$tempArray = array(0=>array(0=>"12",1=>"15",2=>"6"), 1=>array(0=>"6",1=>"9",2=>"11"), 2=>array(0=>"6",1=>"13",2=>"15",3=>"2",4=>"4",5=>"9"));
foreach($tempArray as $key=>$array)
{
echo $key . " Array have " . count($array) . " elements<br><br>";
}
文件夹结构:
/etc/puppetlabs/code
然后,对于我的YAML文件:
[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
然而,当我运行hiera时,我得到以下内容:
[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'
我的[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
时返回不同的内容。
我做错了什么?
答案 0 :(得分:1)
$ facts哈希是由puppet agent / apply设置的,当你尝试通过hiera命令行验证你的设置时,我不希望它可用。
您可以在层次结构中使用- "hostname/%{::hostname}"
来获取hiera cmd的预期结果,或者考虑使用puppet命令行来验证您的设置。