sandeep
sandeep

Reputation: 475

In Chef, how to read an attribute from environment file to chef recipe?

I am downloading files from s3 bucket to aws instance with chef recipe, now my bucket name changes with the environment like dev, qa and prod.

I'm using command like this but its not working, can anyone help?

execute "Downloading files from S3" do
  command "aws s3 sync s3://node['Bucket']/ /prod/users/myfiles/"
  cwd "/prod/"
  action :run
end

I tried s3://#{node['Bucket']}/, but it didn't work.

Chef environment file:

"default_attributes": {
        "Bucket": "s3://mybucket"
}

Upvotes: 0

Views: 381

Answers (2)

How about this?

command "aws s3 sync s3://" + node['Bucket'] + "/ /prod/users/myfiles/"

Upvotes: 0

coderanger
coderanger

Reputation: 54257

If that is really what you have in your environment, node['Bucket'] is correct. You do need the #{} since you are interpolating in a string, so command "aws s3 sync s3://#{node['Bucket']}/ /prod/users/myfiles/"

Upvotes: 0

Related Questions