Chefspec define local variable


#1

Hi guys,

i need to find out how do i define a local variable or attribute in chefspec tests

for instance i have “node” attribute that i used in my recipe. when i test, i get an exception “local variable ‘node’ not defined”

thanks,

Brian


#2

recipe

execute ‘stop Server’ do
user ‘123’
group ‘456’
live_stream true
command “/mypath/ $server -username username -password #{password}”
only_if { ::File.exist?(’/mypath/’+node[:appserver_profile])}


#3

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.


#4

Answered on StackOverflow https://stackoverflow.com/a/50592962/78722