I'm attempting to create an inspec control that searches through every line that starts with kernel (and ignores whitespace) in /boot/grub/grub.conf and then checking every line to see if it has 'nousb' somewhere in the line. I'd like it to return a failure if nousb is not found.
My issue is that I cannot figure out a way to grab/describe multiple stdouts from the grep in the event more than one line starts with kernel. Is that something I can accomplish using .each? Here is my code:
control 'os-disable-usb-pcmcia' do
impact 0.5
title 'Disable USB and PCMCIA Devices'
desc "ensure default kernel in grub has 'nousb' option"
output = command('egrep "^[[:space:]]*kernel" /boot/grub/grub.conf')
describe output do
its('stdout') { should match /^\s*kernel[^#]*nousb\b/ } # match nousb anywhere in the 'kernel' line
end
end
Edit for clarification.
Say I have these lines in my conf file
kernel 1 nousb
kernel 2
kernel 3
kernel 4
the test will consider it passing because the initial one matched what it was looking for despite multiple kernel lines not having the nousb requirement.