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.
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'}
end
}
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