LoginSignup
2
2

More than 5 years have passed since last update.

Chefに入門(2)

Posted at

前回の記事の続きです。パッケージをインストールしてみます。

パッケージをインストールしてみる

前回作ったレシピファイル(default.rb)に追記してパッケージ(zsh)をインストールしてみます。

default.rb
#
# Cookbook Name:: hello
# Recipe:: default
#
# Copyright 2013, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#

log "Hello, Chef!"

package "zsh" do
        action:install
end

実行してみます。

vagrant@precise64:~/chef-repo$ sudo chef-solo -c config.rb -j ./localhost.json 
Starting Chef Client, version 11.6.2
Compiling Cookbooks...
Converging 2 resources
Recipe: hello::default
  * log[Hello, Chef!] action write

  * package[zsh] action install
    - install version 4.3.17-1ubuntu1 of package zsh

Chef Client finished, 2 resources updated

インストールできたか確認してみます。

vagrant@precise64:~/chef-repo$ dpkg -l | grep zsh
ii  zsh                             4.3.17-1ubuntu1            shell with lots of features

できています。
ここがCentOSだろうがUbuntuだろうが同じ設定ファイルでできてしまう(Chefがプラットフォーム間の差異を吸収してくれる)ということになりますすごい。

ここで、もう一度同じコマンドを実行してみます。

vagrant@precise64:~/chef-repo$ sudo chef-solo -c config.rb -j ./localhost.json 
Starting Chef Client, version 11.6.2
Compiling Cookbooks...
Converging 2 resources
Recipe: hello::default
  * log[Hello, Chef!] action write

  * package[zsh] action install (up to date)
Chef Client finished, 1 resources updated

zshの最新版は既にインストールされているので、インストールは実行されませんし、エラーにもなりません。
複数回コマンドを発行してもコマンド発行後のサーバの状態に変化はありません。

この性質を「冪(べき)等性」と言うらしいです。
覚えておくといいみたいです!

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