Issue while using --attrs

Hi All,

I was trying the tutorial on inspec.io http://www.anniehedgie.com/inspec-basics-9
I have created attribute yaml below content.

In attributes.yml

role : base

The inspec rb file is as below

if [‘server’, ‘base’].include? role
control “Testing only server” do
title “Tests for Server”
desc “The following tests within this control will be used for server nodes.”
describe user(‘server’) do
it { should exist }
end
end
end

Executing as below
inspec exec . --attrs attributes/client-attributes.yml

But this gives me error saying role does not exists ideally it should pick up role value from attributes.yml

Could anyone please help me with this?

Thanks and Regards,
Pankaj

You’re using role as if it’s a variable inside your control.

Attribute files define the attribute and its value, but do not define them as variables in your control.

If you’re wanting it to set the role variable to the value in attributes.yaml, then you’d define it in your control as follows:

role = attribute(‘role’, default: ‘base’, description: 'type of node’)

Then when you run your control with the —attrs option you’ll have defined the role variable and it will be set to the value defined for the role attribute in the yaml file.

Hope that helps.

Thank you for clarification.