WhyAyala
WhyAyala

Reputation: 675

Referencing attributes from within a Chef recipe

I have an attribute file titled default.rb with a key in it default['current'] that stores a dir in string format. I wanted to use this for the following command to use when it changes directories:

# Run database migrations
execute 'database migrations' do
  user    'ubuntu'
  cwd     "#{default['current']}"
  command 'sudo php artisan down && sudo php artisan migrate --force && sudo php artisan up'
end

Instead when i ran the recipe i got the following error.

NameError
---------
No resource, method, or local variable named `default' for `Chef::Recipe "deploy"'

Is there a proper way to do this that I'm missing? I'd rather not hard code in the working directory.

Upvotes: 3

Views: 3000

Answers (2)

Jon Malachowski
Jon Malachowski

Reputation: 256

This appears to be answered. But I didn't see a link to the core of the documentation for this(IMO) It is all here: https://docs.chef.io/attributes.html

Upvotes: 0

codeforester
codeforester

Reputation: 42999

When attributes are referenced in a recipe, we need to prefix them with node, like this:

cwd     node['current']

See also: Overriding attributes in the recipe

Upvotes: 3

Related Questions