How to enable inspec.command('ls') on kitchen-docker?

Per the following page,

I should be able to run the following in my …/cook_book/test/integration/default/inspec/default_inspe.rb

But I got
undefined local variable or method `inspec’

How to fix this?

Hi @Victor I am not sure I understand what failed. In your test, your can check for ls in your inspec test

describe command('ls') do
  its('stdout') { should_not eq ''}

Is that answering your question?

chris-rock, what I wanted to do was to obtain file names during compile time. Then use the file names during execution time.
The code in your reply won’t run until execution time. I can’t use its stdout in another resource block such as describe file.

Hi Victor,

inspec.command is called from the resource code. If you want to run a command, use the command resource that Chris pointed out. InSpec has only one phase of execution. I believe the code you are looking for looks like this:

apache_files = command('ls -d /etc/apache2/*').stdout.split("\n")

apache_files.each { |apache_file|
  describe file(apache_file) do
    its('owner') { should eq 'root'}

It gives me the following output:

$ inspec exec ~/tmp/a.rb

Target:  local://

  File /etc/apache2/extra
     ✔  owner should eq "root"
  File /etc/apache2/httpd.conf
     ✔  owner should eq "root"
  File /etc/apache2/magic
     ✔  owner should eq "root"

Test Summary: 3 successful, 0 failures, 0 skipped

Hope this helps,

Worked. Thanks!