Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Chef | resources | bashでbashコマンドの実行

概要

bashbashコマンドの実行

詳細

bashbashコマンドの実行をします。
Chefで提供されている機能では出来ないことがある場合などに利用します。

.bash_profileにエイリアスを追記して再読込
home = "/home/user_name"
bash "insert_line" do
  user "root"
  code <<-EOS
  echo "alias='vi=vim' >> #{home}/.bash_profile
  source #{home}/.bash_profile
  EOS
end
.bash_profileにエイリアスを追記して再読込(environment Attributeを利用した例)

2014/01/19追記:llbyさんから頂いたコメントを参考に致しました。ありがとうございます。

home = "/home/user_name"
bash "insert_line" do
  user "root"
  environment "HOME" => "/home/vagrant"
  code <<-EOS
  echo "alias='vi=vim' >> ~/.bash_profile
  source ~/.bash_profile
  EOS
end

参照

その他詳細については下記公式ドキュメント参照
http://docs.opscode.com/resource_bash.html