告诉Inspec在OS版本A上运行测试X,在OS版本B上运行测试Y的惯用方法是什么?我知道技术将主厨node对象转储到/tmp中的JSON文件中,但这并不是为我所做的,因为它运行在Test中,而Inspec在真正的主机上执行.却看不到它。
发布于 2018-11-20 22:49:51
我所建议的,就像你下面的评论,是把这个带到#inspec频道的厨师社区斯拉克问那里。话虽如此,我可以这样攻击它:
control 'some-control-slug' do
title 'My control'
impact 1.0
desc 'Example code for Stack Exchange'
if os.windows? && ::Gem::Version.new(os.release) < ::Gem::Version.new('6.1')
# Only executed on Windows machines older than 2008r2
describe directory('C:/Users') do
it { should exist }
end
elsif os.windows? && ::Gem::Version.new(os.release) >= ::Gem::Version.new('10')
# Only executed on Windows Server 2016 or newer
describe directory('D:/MyFolder') do
it { should_not exist }
end
end
# Executed on all host types
describe sys_info do
its('hostname') { should match(/SomeAwesomeHost/i) }
end
end此外,您还可以使用类似厨师的钩子(如only_if )来限制整个inspec控件。上面编写的示例代码可以在Linux目标上执行。我们可以通过在desc或title附近放置以下内容来限制它们:
only_if { os.windows? }https://devops.stackexchange.com/questions/5037
复制相似问题