I have a test :
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
This displays the following on stdout:
$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
How do i use Inspec ( if possible ) or use ruby to parse and verify ( assert ) these multiple lines.
as @coderanger suggested i used:
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
Works!! thanks
Why are you using Open3
? You want to be using the command
resource, not direct Ruby command execution. That said, you would just compare to a string with \n
in it.