cars
cars

Reputation: 441

Chef recipe use ubuntu environmental variables

I have a chef recipe which I am looking to utilize the ubuntu environment variables from the system:

bash "proj s3 sync" do
  code "AWS_ACCESS_KEY_ID=#{ENV['AWS_ACCESS_ID']} AWS_SECRET_ACCESS_KEY=#{ENV['AWS_SECRET']} aws command..."
  cwd     "/home/#{node['deploy']['chef-environment']}"
  user    "#{node['deploy']['chef-environment']}"
  environment ({
    'HOME' => ::Dir.home(node['deploy']['chef-environment']),
    'USER' => node['deploy']['chef-environment'],
  })
  ignore_failure false
end

When executing this recipe, the env vars are empty. But from the same machine, doing EG echo $AWS_ACCESS_ID returns result as expected.

Is there something wrong with my use of the ruby ENV syntax in this chef recipe? Or another reason the scope of ENV would not possess the properties needed?

Upvotes: 0

Views: 237

Answers (2)

cars
cars

Reputation: 441

In my context, this implementation was for an AWS server.

AWS offers interface to environment variables for machines managed via opsworks with chef via recipe aws_opsworks_app:

http://docs.aws.amazon.com/opsworks/latest/userguide/data-bag-json-app.html

Upvotes: 0

coderanger
coderanger

Reputation: 54181

So you are using ENV directly there, meaning getting stuff from chef-client's environment. And because chef-client is generally run either directly via SSH (without a shell) or as a service (again, no shell) so all your shell initialization files do not get loaded. Remember that Unix has no concept of a "global environment variable" or "system environment variable". You'll want (or need) to use some kind of config file instead.

Upvotes: 1

Related Questions