LoginSignup
34
31

More than 5 years have passed since last update.

Chef の not_if についてのメモ

Last updated at Posted at 2013-10-19

Chef を使っていると、not_if を使うケースが多くなると思います。
not_if の条件や、オプションについて備忘録を残したくなったので投稿します。

すべて、次のページに書いてある内容です。
http://docs.opscode.com/resource_template.html

まずは、ある特定のファイルがないときに command execute したいときの書き方。基本的な書き方ですね。

execute "aaa" do
  command "git clone https://github.com/aaa"
  not_if { File.exists?("/home/vagrant/aaa") }
end

次に、template です。template にも not_if 渡せること知りませんでした。(勉強不足)
また、not_if で grep 渡せること知りませんでした。(これも勉強不足)

environment で環境変数をハッシュで渡せるっていうの、ずっと知りませんでした。
これ知っていたらあちこちでもっと楽できたような気がする…

template ".bash_profile" do
  source ".bash_profile.erb"
  path   "/home/vagrant/.bash_profile"
  mode   0644
  owner  "vagrant"
  group  "vagrant"
  not_if "grep aaa ~/.bash_profile", :environment => { :'HOME' => "/home/vagrant" }
end
34
31
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
34
31