- puppet入門1 準備編
- puppet入門2 パッケージをインストールしてみる
- puppet入門3 ファイルを配布
- puppet入門4 ハマった場合の対処とか
- puppet入門5 ユーザー、グループの追加
- puppet入門6 puppetのclientを追加する
- puppet入門7 ファイルに変更があった時にサービスをrestartさせる
puppet入門1 準備編の続き。
今回も1台構成(自分自身がmasterでありclient)で。
流れ
- /etc/puppet/manifests/site.ppを作成する。
- puppet実行してsite.ppに書いてある内容を実行してもらう。
パッケージのインストール
site.pp
node 'puppetmaster.safe' {
package { ['w3m',
'nkf']:
ensure => installed,
}
}
# 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
/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がインストールされたことを確認。
ホストごとに処理を分ける
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
がインストール。
# 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
/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つ書いてはいけない
node node 'puppetmaster.safe' {
}
node node 'puppetmaster.safe' {
}
/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
$ facter
を実行するとpuppetで使える変数一覧を取得できる。
処理を分岐させるのに必須。