1

I put credentials into an s3 bucket and I use a ruby block to grab them. I then want to set an environment variable such that when upstart starts a process it uses this variable. However the block of ruby runs after attributes are set so I thought using lazy would be appropriate, but it's not clear to me how to set env using lazy.

Would it be something like:

ruby_block "get-credentials" do
  block do
    Chef::Log.info 'Getting sdk.'
    require 'aws-sdk'

    Chef::Log.info 'Getting making aws s3 instance.'
    s3 = AWS::S3.new


    Chef::Log.info 'Getting credentials from s3.'
    bar = s3.buckets['bucket-name'].objects['bar'].read
    Chef::Log.info 'Got bar with length #{bar.length}'

    node.set['foo']['bar'] = bar

  end
  action :run
end

env lazy BAR=node.set['foo']['bar']

service 'foo' do
    provider Chef::Provider::Service::Upstart
    action [ :enable, :start ]
end

I'm not sure. I am still looking through the documentation and experimenting but maybe someone knows. The turn around on testing different variations is taking a really long time.

Bjorn
  • 69,215
  • 39
  • 136
  • 164

1 Answers1

3

The env resource only works on Windows, it has nothing to do with Linux. If you want to define environment variables for an upstart service it has to go in the upstart config, as the environment within Chef has no effect on things spawned from upstart.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Yes the documentation was confusing to me. The line about using `env` in upstart was in an upstart template, not the ruby recipe file! This worked. Thank you! – Bjorn Feb 13 '16 at 20:06