LoginSignup
5
2

More than 5 years have passed since last update.

Chef実行時に必要な環境変数の設定方法

Last updated at Posted at 2015-02-26
execute "go get github.com/github/hub" do
  environment "GOPATH" => "/root/gocode"
end

こんな感じでこのrecipeを実行する時に必要な環境変数を設定できます。(永続的な環境変数ではありません)

一度のchef-soloの実行内でこの処理の前にbashのprofile等で環境変数を設定したりしているかもしれませんが、一度の実行中だと反映されていません。なので、そのコマンドで必要な環境変数は、上記のようにenvironment attributeで設定する必要があります。

なお、複数の環境変数を設定したい場合は以下のようにします。

execute "go get github.com/github/hub" do
  environment(
   "GOPATH" => "/root/gocode",
   "PATH" => "/usr/local/go/bin:#{ENV["PATH"]}"
  )
end

参考:

https://docs.chef.io/resource_execute.html
http://d.hatena.ne.jp/rougeref/20141217

5
2
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
5
2