【发布时间】:2017-12-18 15:46:34
【问题描述】:
我有一个测试:
control "cis-0-0-7" do
impact 1.0
title "verify chkconfig"
desc "verify chkconfig"
stdout, stderr, status = Open3.capture3('chkconfig | grep active')
puts stdout
#stdout { should match /activemq-instance-EL2-ext/ }
#end
end
这会在标准输出上显示以下内容:
$inspec exec cookbooks/activemq7/test/linuxcommon_test.rb
activemq-instance-EL2-ext 0:off 1:off 2:on 3:on 4:on 5:on 6:off
activemq-instance-EL2-int 0:off 1:off 2:on 3:on 4:on 5:on 6:off
我如何使用 Inspec(如果可能)或使用 ruby 来解析和验证(断言)这些多行。
正如@coderanger 建议我使用的那样:
control "cis-0-0-7" do
impact 1.0
title "verify chkconfig"
desc "verify chkconfig"
#stdout, stderr, status = Open3.capture3('chkconfig | grep active')
output = command('chkconfig | grep active')
describe output do
its('stdout') { should match /activemq-instance-EL2-ext.*\n/ }
its('stdout') { should match /activemq-instance-EL2-int.*\n/ }
end
end
有效!!谢谢
【问题讨论】:
-
你仍然不需要变量,只需要
describe command(...),现在我费心阅读你的代码,你为什么 1) 不使用service()资源和 2) 不使用现有的CIS 基准测试模块?
标签: ruby parsing chef-infra inspec