puppet入門2 パッケージをインストールしてみる

* [puppet入門1 準備編](http://qiita.com/tukiyo/items/54c32ecfb8cc6cd76073)
* [puppet入門2 パッケージをインストールしてみる](http://qiita.com/tukiyo/items/e47dfc77ac40052ed04c)
* [puppet入門3 ファイルを配布](http://qiita.com/tukiyo/items/0003a54e47bf768133e2)
* [puppet入門4 ハマった場合の対処とか](http://qiita.com/tukiyo/items/d05bf0b705fd473adc55)
* [puppet入門5 ユーザー、グループの追加](http://qiita.com/tukiyo/items/e15dabc6174b475728fc)
* [puppet入門6 puppetのclientを追加する](http://qiita.com/tukiyo/items/261beec159f17a457d02)
* [puppet入門7 ファイルに変更があった時にサービスをrestartさせる](http://qiita.com/tukiyo3/items/0eef6e1a97d89b0149e4)



[puppet入門1 準備編](http://qiita.com/tukiyo/items/54c32ecfb8cc6cd76073)の続き。
今回も１台構成(自分自身がmasterでありclient)で。

流れ
------
* /etc/puppet/manifests/site.ppを作成する。
* puppet実行してsite.ppに書いてある内容を実行してもらう。

パッケージのインストール
====================

```bash:site.pp
node 'puppetmaster.safe' {
  package { ['w3m',
             'nkf']:
    ensure => installed,
  } 
}
```


```bash:
# puppet agent --server=puppetmaster.safe --no-daemonize --verbose
Notice: Starting Puppet client version 3.3.2
Info: Retrieving plugin
Info: Caching catalog for puppetmaster.safe
Info: Applying configuration version '1385076612'
Notice: /Stage[main]//Node[puppetmaster.safe]/Package[nkf]/ensure: created
Notice: /Stage[main]//Node[puppetmaster.safe]/Package[w3m]/ensure: created
Notice: Finished catalog run in 4.23 seconds
```

```bash:/var/log/messages
Nov 22 02:30:11 puppetmaster puppet-agent[1712]: Starting Puppet client version 3.3.2
Nov 22 02:30:11 puppetmaster puppet-agent[1717]: Retrieving plugin
Nov 22 02:30:12 puppetmaster puppet-master[916]: Compiled catalog for puppetmaster.safe in environment production in 0.31 seconds
Nov 22 02:30:13 puppetmaster puppet-agent[1717]: Caching catalog for puppetmaster.safe
Nov 22 02:30:13 puppetmaster puppet-agent[1717]: Applying configuration version '1385076612'
Nov 22 02:30:14 puppetmaster yum: Installed: nkf-2.07-1.1.fc6.i386
Nov 22 02:30:14 puppetmaster puppet-agent[1717]: (/Stage[main]//Node[puppetmaster.safe]/Package[nkf]/ensure) created
Nov 22 02:30:17 puppetmaster yum: Installed: w3m-0.5.1-18.el5.i386
Nov 22 02:30:17 puppetmaster puppet-agent[1717]: (/Stage[main]//Node[puppetmaster.safe]/Package[w3m]/ensure) created
Nov 22 02:30:17 puppetmaster puppet-agent[1717]: Finished catalog run in 4.23 seconds
```

* w3mとnkfがインストールされたことを確認。


ホストごとに処理を分ける
===================

```bash:site.pp
node 'puppetmaster.safe' {
  package { ['w3m',
             'nkf',
             'ctags']:
    ensure => installed,
  } 
}

node 'www.safe' {
  package { ['php53-cli']:
    ensure => installed,
  } 
}

node default {
  package { ['ntp']:
    ensure => installed,
  } 
}
```

* puppetmaster.safe に `nkf`と`w3m`と`ctags`がインストール
* www.safe に `php53-cli`がインストール
* ホスト名が`puppetmaster.safe`と`www.safe`にマッチしない場合、`ntp`がインストール。
  * [公式サイトのドキュメント](http://docs.puppetlabs.com/puppet/2.7/reference/lang_node_definitions.html#the-default-node)

```bash:
# puppet agent --server=puppetmaster.safe --no-daemonize --verbose
Notice: Starting Puppet client version 3.3.2
Info: Retrieving plugin
Info: Caching catalog for puppetmaster.safe
Info: Applying configuration version '1385077372'
Notice: /Stage[main]//Node[puppetmaster.safe]/Package[ctags]/ensure: created
Notice: Finished catalog run in 1.98 seconds
```

```bash:/var/log/messages
Nov 22 02:42:51 puppetmaster puppet-agent[2171]: Starting Puppet client version 3.3.2
Nov 22 02:42:51 puppetmaster puppet-agent[2176]: Retrieving plugin
Nov 22 02:42:52 puppetmaster puppet-master[916]: Compiled catalog for puppetmaster.safe in environment production in 0.01 seconds
Nov 22 02:42:52 puppetmaster puppet-agent[2176]: Caching catalog for puppetmaster.safe
Nov 22 02:42:52 puppetmaster puppet-agent[2176]: Applying configuration version '1385077372'
Nov 22 02:42:54 puppetmaster yum: Installed: ctags-5.6-1.1.i386
Nov 22 02:42:54 puppetmaster puppet-agent[2176]: (/Stage[main]//Node[puppetmaster.safe]/Package[ctags]/ensure) created
Nov 22 02:42:54 puppetmaster puppet-agent[2176]: Finished catalog run in 1.98 seconds
```

注意点
=======

同じnodeを2つ書いてはいけない
---------------

```bash:
node node 'puppetmaster.safe' {
}
node node 'puppetmaster.safe' {
}
```

```bash:/var/log/messages
Nov 22 02:51:28 puppetmaster puppet-agent[2732]: Could not retrieve catalog from remote server: Error 400 on SERVER: Node 'puppetmaster.safe' is already defined at /etc/puppet/manifests/site.pp:7; cannot redefine at /etc/puppet/manifests/site.pp:15 on node puppetmaster.safe
```

facter
========

```bash:
$ facter
```

を実行するとpuppetで使える変数一覧を取得できる。
処理を分岐させるのに必須。


* [puppet入門3 ファイルを配布](http://qiita.com/tukiyo/items/0003a54e47bf768133e2)に続く。