明天就可以了。没问题,谢谢。我现在在家,我更确信我做错了什么,因为同样的事情发生在我的测试实验室。我会调查更多并发布更新。我已经用更多的信息编辑了我的原始帖子。谢谢,乔恩。干得好。非常感谢你。我对puppet还比较陌生,我正在学习这门课程,并且已经预约了考

明天就可以了。没问题,谢谢。我现在在家,我更确信我做错了什么,因为同样的事情发生在我的测试实验室。我会调查更多并发布更新。我已经用更多的信息编辑了我的原始帖子。谢谢,乔恩。干得好。非常感谢你。我对puppet还比较陌生,我正在学习这门课程,并且已经预约了考,puppet,hiera,Puppet,Hiera,明天就可以了。没问题,谢谢。我现在在家,我更确信我做错了什么,因为同样的事情发生在我的测试实验室。我会调查更多并发布更新。我已经用更多的信息编辑了我的原始帖子。谢谢,乔恩。干得好。非常感谢你。我对puppet还比较陌生,我正在学习这门课程,并且已经预约了考试,但是我的要求很快超过了我的知识。我没听说过Rspec木偶。我现在一直在读,它看起来很有趣昨晚我发现,尽管我犯了错误,hiera实际上还是在工作,如果我使用木偶查找而不是hiera二进制文件,它工作得很好。所以这可能是hiera二进制的一个限


明天就可以了。没问题,谢谢。我现在在家,我更确信我做错了什么,因为同样的事情发生在我的测试实验室。我会调查更多并发布更新。我已经用更多的信息编辑了我的原始帖子。谢谢,乔恩。干得好。非常感谢你。我对puppet还比较陌生,我正在学习这门课程,并且已经预约了考试,但是我的要求很快超过了我的知识。我没听说过Rspec木偶。我现在一直在读,它看起来很有趣昨晚我发现,尽管我犯了错误,hiera实际上还是在工作,如果我使用木偶查找而不是hiera二进制文件,它工作得很好。所以这可能是hiera二进制的一个限制。感谢您的解释和解决方法,这需要一些理解,但我刚刚使用::fqdn=进行了检查,它是有效的。Rspec-puppet是puppet基础中他们不会告诉您的东西,但我发现它是最有用的理解之一。当您设置好测试工具后,测试和调试Puppet代码突然变得非常容易。
cat common.yaml
---
resolv_conf::nameserver:
- x.x.x.x
- x.x.x.x

profile::ntp::servers:
- x.x.x.x
- x.x.x.x
hiera resolv_conf::nameservers environment=production
["x.x.x.x", "x.x.x.x"]
cat nodes/fqdn.yaml
---
profile::ntp::servers:
-1.1.1.1
-2.2.2.2
cat hiera.yaml
---
:backends: yaml
:yaml:
  :datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata"
:hierarchy:
  -"nodes/%{::fqdn}"
  - "common"

:logger: console
:merge_behavior: native
:deep_merge_options: {}
hiera profile::ntp::servers environment=production -d
[root@client-01 nodes]# pwd
/root/control-repo/hieradata/nodes
[root@client-01 nodes]# ll
total 8
-rw-r--r--. 1 root root 34 Jul 13 19:04 puppet.example.com.yaml
-rw-r--r--. 1 root root 18 Jul 13 18:58 test.yaml
[root@client-01 nodes]# cat puppet.example.com.yaml
---
message:
- "This is in nodes"
[root@puppet ~]# hostname -f
puppet.example.com
[root@puppet ~]# hiera message environment=production
nil
[root@puppet ~]# hiera message environment=production 
fqdn=puppet.example.com
nil
[root@puppet ~]# hiera message environment=production fqdn=puppet.example.com -d
DEBUG: 2017-07-13 19:28:15 +0100: Hiera YAML backend starting
DEBUG: 2017-07-13 19:28:15 +0100: Looking up message in YAML backend
DEBUG: 2017-07-13 19:28:15 +0100: Ignoring bad definition in :hierarchy: 'nodes/'
DEBUG: 2017-07-13 19:28:15 +0100: Looking for data source common
nil
[root@puppet ~]#
[root@puppet ~]# cat /etc/puppetlabs/puppet/hiera.yaml
---
:backends:
  - yaml
:hierarchy:
  - "nodes/%{::fqdn}"
  - common

:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /etc/puppetlabs/code/environments/%{environment}/hieradata on *nix
# - %CommonAppData%\PuppetLabs\code\environments\%{environment}\hieradata on Windows
# When specifying a datadir, make sure the directory exists.
  :datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata"
[root@client-01 hieradata]# pwd ; ll ; cat test.yaml
/root/control-repo/hieradata
total 12
-rw-r--r--. 1 root root  4 Jul 13 19:25 common.yaml
drwxr-xr-x. 2 root root 52 Jul 13 19:04 nodes
-rw-r--r--. 1 root root 19 Jul 13 21:47 puppet.example.com.yaml
-rw-r--r--. 1 root root 18 Jul 13 21:43 test.yaml
---
name:
- "jon"
[root@client-01 hieradata]# pwd ; ll ; cat puppet.example.com.yaml
/root/control-repo/hieradata
total 12
-rw-r--r--. 1 root root  4 Jul 13 19:25 common.yaml
drwxr-xr-x. 2 root root 52 Jul 13 19:04 nodes
-rw-r--r--. 1 root root 19 Jul 13 21:47 puppet.example.com.yaml
-rw-r--r--. 1 root root 18 Jul 13 21:43 test.yaml
---
test:
- "pass"
[root@puppet ~]# hostname -f ; hiera test environment=production -d
puppet.example.com
DEBUG: 2017-07-13 21:53:44 +0100: Hiera YAML backend starting
DEBUG: 2017-07-13 21:53:44 +0100: Looking up test in YAML backend
DEBUG: 2017-07-13 21:53:44 +0100: Ignoring bad definition in :hierarchy: 
'nodes/'
DEBUG: 2017-07-13 21:53:44 +0100: Ignoring bad definition in :hierarchy: ''
DEBUG: 2017-07-13 21:53:44 +0100: Looking for data source test
DEBUG: 2017-07-13 21:53:44 +0100: Looking for data source common
nil
[root@puppet ~]# hostname -f ; hiera test environment=production 
fqdn=puppet.example.com -d
puppet.example.com
DEBUG: 2017-07-13 21:53:57 +0100: Hiera YAML backend starting
DEBUG: 2017-07-13 21:53:57 +0100: Looking up test in YAML backend
DEBUG: 2017-07-13 21:53:57 +0100: Ignoring bad definition in :hierarchy: 
'nodes/'
DEBUG: 2017-07-13 21:53:57 +0100: Ignoring bad definition in :hierarchy: ''
DEBUG: 2017-07-13 21:53:57 +0100: Looking for data source test
DEBUG: 2017-07-13 21:53:57 +0100: Looking for data source common
nil
[root@puppet ~]# facter fqdn
puppet.example.com
[root@puppet ~]# hostname -f
puppet.example.com
-"nodes/%{::fqdn}"
hiera profile::ntp::servers environment=production fqdn=fqdn -d
cat nodes/myhost.example.com.yaml
---
profile::ntp::servers:
-1.1.1.1
-2.2.2.2
# nodes/myhost.example.com.yaml
---
profile::ntp::servers:
- 1.1.1.1
- 2.2.2.2
# hiera test environment=production fqdn=puppet.example.com -d
# hiera test environment=production ::fqdn=puppet.example.com -d
$ cat manifests/init.pp 
class foo (
  $servers,
  $nameserver,
) {
  notify { "servers: $servers": }
  notify { "nameserver: $nameserver": }
}
$ cat spec/fixtures/hiera/hiera.yaml 
---
:backends:
  - yaml
:hierarchy:
  - "nodes/%{::fqdn}"
  - common
:yaml:
  :datadir: 'spec/fixtures/hieradata'
:logger: console
:merge_behavior: native
:deep_merge_options: {}
$ cat spec/fixtures/hieradata/common.yaml 
---
foo::nameserver:
- 3.3.3.3
- 4.4.4.4

foo::servers:
- 5.5.5.5
- 6.6.6.6
$ cat spec/fixtures/hieradata/nodes/myhost.example.com.yaml 
---
foo::servers:
- 1.1.1.1
- 2.2.2.2
$ cat spec/spec_helper.rb 
require 'puppetlabs_spec_helper/module_spec_helper'

RSpec.configure do |c|
  c.hiera_config = 'spec/fixtures/hiera/hiera.yaml'
  c.default_facts = {
    :fqdn => 'myhost.example.com',
  }
end
$ cat spec/classes/test_spec.rb 
require 'spec_helper'

describe 'foo', :type => :class do
  it { File.write('myclass.json', PSON.pretty_generate(catalogue)) }
end
$ bundle exec rake spec 
...
Finished in 0.15682 seconds (files took 0.97868 seconds to load)
1 example, 0 failures
$ bundle exec puppet apply --environment=rp_env --catalog=myclass.json 
Notice: servers: [1.1.1.1, 2.2.2.2]
Notice: /Stage[main]/Foo/Notify[servers: [1.1.1.1, 2.2.2.2]]/message: defined 'message' as 'servers: [1.1.1.1, 2.2.2.2]'
Notice: nameserver: [3.3.3.3, 4.4.4.4]
Notice: /Stage[main]/Foo/Notify[nameserver: [3.3.3.3, 4.4.4.4]]/message: defined 'message' as 'nameserver: [3.3.3.3, 4.4.4.4]'
Notice: Applied catalog in 0.02 seconds
$ bundle exec puppet apply --environment=rp_env --catalog=myclass.json 
Notice: servers: [5.5.5.5, 6.6.6.6]
Notice: /Stage[main]/Foo/Notify[servers: [5.5.5.5, 6.6.6.6]]/message: defined 'message' as 'servers: [5.5.5.5, 6.6.6.6]'
Notice: nameserver: [3.3.3.3, 4.4.4.4]
Notice: /Stage[main]/Foo/Notify[nameserver: [3.3.3.3, 4.4.4.4]]/message: defined 'message' as 'nameserver: [3.3.3.3, 4.4.4.4]'
Notice: Applied catalog in 0.01 seconds
$ bundle exec hiera foo::servers environment=rp_env -d -c spec/fixtures/hiera/hiera.yaml 
DEBUG: 2017-07-15 13:21:54 +1000: Hiera YAML backend starting
DEBUG: 2017-07-15 13:21:54 +1000: Looking up foo::servers in YAML backend
DEBUG: 2017-07-15 13:21:54 +1000: Ignoring bad definition in :hierarchy: 'nodes/'
DEBUG: 2017-07-15 13:21:54 +1000: Looking for data source common
DEBUG: 2017-07-15 13:21:54 +1000: Found foo::servers in common
["5.5.5.5", "6.6.6.6"]
$ bundle exec hiera foo::servers fqdn=myhost.example.com environment=rp_env -d -c spec/fixtures/hiera/hiera.yaml 
DEBUG: 2017-07-15 13:23:34 +1000: Hiera YAML backend starting
DEBUG: 2017-07-15 13:23:34 +1000: Looking up foo::servers in YAML backend
DEBUG: 2017-07-15 13:23:34 +1000: Ignoring bad definition in :hierarchy: 'nodes/'
DEBUG: 2017-07-15 13:23:34 +1000: Looking for data source common
DEBUG: 2017-07-15 13:23:34 +1000: Found foo::servers in common
["5.5.5.5", "6.6.6.6"]
$ bundle exec hiera foo::servers ::fqdn=myhost.example.com environment=rp_env -d -c spec/fixtures/hiera/hiera.yaml 
DEBUG: 2017-07-15 13:24:09 +1000: Hiera YAML backend starting
DEBUG: 2017-07-15 13:24:09 +1000: Looking up foo::servers in YAML backend
DEBUG: 2017-07-15 13:24:09 +1000: Looking for data source nodes/myhost.example.com
DEBUG: 2017-07-15 13:24:09 +1000: Found foo::servers in nodes/myhost.example.com
["1.1.1.1", "2.2.2.2"]