Cannot find profile files error


#1

I’m trying out the example using profile files but when I run it I get the following error:

Cannot find file services.yml in profile.

Or when I run inspec check

/home/user/.gem/gems/inspec-2.1.59/lib/inspec/runtime_profile.rb:23:in `file': Cannot find file services.yml in profile. (RuntimeError)
	from controls/example-file.rb:6:in `load_with_context'
	from /home/user/.gem/gems/inspec-2.1.59/lib/inspec/profile_context.rb:158:in `instance_eval'
	from /home/user/.gem/gems/inspec-2.1.59/lib/inspec/profile_context.rb:158:in `load_with_context'
	from /home/user/.gem/gems/inspec-2.1.59/lib/inspec/profile_context.rb:142:in `load_control_file'
	from /home/user/.gem/gems/inspec-2.1.59/lib/inspec/profile.rb:170:in `block in collect_tests'
	from /home/user/.gem/gems/inspec-2.1.59/lib/inspec/profile.rb:167:in `each'
	from /home/user/.gem/gems/inspec-2.1.59/lib/inspec/profile.rb:167:in `collect_tests'
	from /home/user/.gem/gems/inspec-2.1.59/lib/inspec/profile.rb:473:in `load_checks_params'
	from /home/user/.gem/gems/inspec-2.1.59/lib/inspec/profile.rb:466:in `load_params'
	from /home/user/.gem/gems/inspec-2.1.59/lib/inspec/profile.rb:160:in `params'
	from /home/user/.gem/gems/inspec-2.1.59/lib/inspec/profile.rb:326:in `controls_count'
	from /home/user/.gem/gems/inspec-2.1.59/lib/inspec/profile.rb:297:in `check'
	from /home/user/.gem/gems/inspec-2.1.59/lib/inspec/cli.rb:76:in `check'
	from /home/user/.gem/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	from /home/user/.gem/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	from /home/user/.gem/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	from /home/user/.gem/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
	from /home/user/.gem/gems/inspec-2.1.59/bin/inspec:12:in `<top (required)>'
	from /home/user/.gem/bin/inspec:23:in `load'
	from /home/user/.gem/bin/inspec:23:in `<main>'

% inspec --version
2.1.59
% ruby --version
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

I’ve tried to load in all manners I could fine online:

my_services = yaml(content: inspec.profile.file('services.yml')).params

my_services = YAML.load(inspec.profile.file('services.yml'))

content = inspec.profile.file("services.yml")
my_services = YAML.parse(content)


#2

Hi @ruud.goossens

I usually do it this way

  • ./controls/default.rb
_default = YAML.load_file(File.join(File.dirname(__FILE__), '../attributes/default.yml'))

This is the following structure I use in this case

.
β”œβ”€β”€ attributes
β”‚   └── default.yml
β”œβ”€β”€ controls
β”‚   └── default.rb
β”œβ”€β”€ inspec.yml
└── README.md


#3

Thanks, that works. It seems that the inspec.profile.file method contains some kind of bug?


#4

It should work… were your files placed in the ./files/ folder within your profile?
Here is the github issue where they discussed the implementation of this feature:


#5

Yes, files are placed in ./files directory in the profile dir.

I’ve retested with use of the docker workstation container that was created as part of the Inspec tutorial. Same issue, so I’m really starting to think this is a bug. How can I create a bug report?

% docker exec -it workstation bash
root@3b13b29b652b:/# cd /root
root@3b13b29b652b:~# inspec init profile example
Create new profile at /root/example
 * Create file README.md
 * Create directory controls
 * Create file controls/example.rb
 * Create file inspec.yml
 * Create directory libraries
root@3b13b29b652b:~# mkdir -p example/files         
root@3b13b29b652b:~# vi example/files/services.yml
root@3b13b29b652b:~# vi example/controls/example.rb 
root@3b13b29b652b:~# inspec exec example/controls/example.rb 
Cannot find file services.yml in profile.

root@3b13b29b652b:~# tree example/
example/
|-- README.md
|-- controls
|   `-- example.rb
|-- files
|   `-- services.yml
|-- inspec.yml
`-- libraries

3 directories, 4 files

example/controls/example.rb

# encoding: utf-8
# copyright: 2018, The Authors

title 'sample section'

my_services = yaml(content: inspec.profile.file('services.yml')).params

my_services.each do |s|
  describe service(s['service_name']) do
    it { should be_running }
  end

  describe port(s['port']) do
    it { should be_listening }
  end
end

example/files/services.yml

- service_name: httpd-alpha
  port: 80
- service_name: httpd-beta
  port: 8080