LoginSignup
8
6

More than 5 years have passed since last update.

chef の execute で bundle exec 実行する

Last updated at Posted at 2015-03-02

execute の user を指定しても、HOME と USER 環境変数は更新されず、chef 実行ユーザの環境変数のままとなる。それだとおかしいことになるのできちんと設定してあげると良い.

execute 'test' do
  user 'sonots'
  cwd  '/home/sonots/app_name'
  command '/home/sonots/.rbenv/versions/2.2.0/bin/bundle exec env > /tmp/env'
  environment(
    'HOME' => '/home/sonots',
    'USER' => 'sonots',
  )
end

あとは、chef-solo を bundle exec 付きで実行しないこと。bundler の環境変数が設定されて、execute リソースでコマンドを fork + exec した場合に、環境変数が残ってしまい、command で指定した bundle exec が利かなくなる。

通常の ruby スクリプトであれば、Bundler.with_clean_env ブロックで囲んであげれば良いのだが、chef の execute リソースの場合、別のスコープで実行されるので利かない。

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6