问题
如果变量可以传递给Puppet类,例如:
class module_name (
$variable='hello_world'
) {
package { 'package_name': }
}
和rspec
运行失败,即:
[user@host module_name]$ rspec
...............................FFFFFFFFFFFF..........................................
Failures:
1) opsview should contain Class[module_name]
Failure/Error: it { should contain_class('module_name') }
Puppet::Error:
Error from DataBinding 'hiera' while looking up 'module_name::variable':
FileSystem implementation expected Pathname, got: 'Hash' on node host
# /usr/share/ruby/vendor_ruby/puppet/resource.rb:393:
in `rescue in lookup_with_databinding'
# /usr/share/ruby/vendor_ruby/puppet/resource.rb:387:
in `lookup_with_databinding'
# /usr/share/ruby/vendor_ruby/puppet/resource.rb:381:
in `lookup_external_default_for'
主要问题
Error from DataBinding while looking up FileSystem implementation expected Pathname,
got: 'Hash' on node
配置
版本
[vagrant@vm-one opsview]$ puppet --version
3.7.5
[vagrant@vm-one opsview]$ rspec --version
3.2.2
Spec_helper
[vagrant@vm-one opsview]$ cat spec/spec_helper.rb
require 'rspec-puppet'
require 'hiera-puppet-helper'
fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
RSpec.configure do |c|
c.module_path = File.join(fixture_path, 'modules')
c.manifest_dir = File.join(fixture_path, 'manifests')
c.hiera_config = '/etc/puppet/hiera.yaml'
end
at_exit { RSpec::Puppet::Coverage.report! }
尝试
答案 0 :(得分:0)
hiera_config
存在问题,应该是:
c.hiera_config = 'spec/fixtures/hiera/hiera.yaml'
假设您有以下目录结构:
\spec
\fixtures
\hiera
hiera.yaml
default.yaml
和hiera.yaml
:
---
:backends:
- yaml
:hierarchy:
- '%{::clientcert}'
- default
:yaml:
:datadir: './spec/fixtures/hiera'
确实不需要hiera-puppet-helper
宝石,实际上它不应该存在。我建议使用Garethr's skeleton生成模块结构,其中已经包含了Hiera的工作设置,可以为您节省大量时间。