前回に引き続き、
データファイルの階層構造
Puppet本家WikiのPuppet Best Practiceでは、
distディレクトリには、
manifestsディレクトリにはマニフェストを置きます。site.
templatesディレクトリ以下にはクラスごとにディレクトリを作成してテンプレートファイルを置きます。templates/{classname}以下の構造はdist/{classname}以下と同様です。
modulesディレクトリにはモジュールを置きます。
マニフェストのコーディングスタイル
Puppet本家WikiのStyle Guideでは、
矢印(=>)の配置  
矢印の配置は、
exec {
    'blah':
        path => '/usr/bin',
        cwd  => '/tmp';
    'test':
        subscribe   => '/etc/test',
        refreshonly => true;
}
ただし、
exec {
    'blah':
        path        => 'usr/bin',
        cwd         => '/tmp';
    'test':
        subscribe   => '/etc/test',
        refreshonly => true;
}
クォート
予約語や、
file { '/tmp/somefile':
    ensure => present,
    owner  => 'root',
    group  => "$group",
}
カンマ
最後のパラメータ行もカンマで終えるようにします。こうしておくと、
file { "/tmp/somefile":
    ensure => exists,
    owner  => 'root',
}
リソースの宣言
パラメータがひとつしかないリソースは、
file { '/tmp/somefile': ensure => exists }
同じタイプのリソースを複数宣言する場合は、
file {
    '/tmp/app':
        ensure => directory;
    '/tmp/app/file':
        ensure => exists,
        owner  => 'webapp';
    '/tmp/app/file2':
        ensure => exists,
        owner  => 'webapp',
        mode   => 755;
}
シンボリックリンク
シンボリックリンクは以下のように宣言できますが、これは推奨されない例です。
file { '/var/log/syslog':
    ensure => '/var/log/messages',
}
シンボリックリンクであることを明確にするために、
file { '/var/log/syslog':
    ensure => link,
    target => '/var/log/messages',
}
レポーティング
Puppetにはマニフェストの適用結果をレポートする機能があります。レポートの種類としては、
レポート機能のための設定
Puppetクライアント側での設定
レポート機能を利用するためには、
コマンドラインオプションの場合、puppetd実行時に以下のように--reportオプションを指定します。
$ sudo puppetd --report
設定ファイルの場合、0.
report = true
0.
[puppetd]
    report = true
Puppetサーバ側での設定
Puppetサーバ側では、
コマンドラインオプションの場合、puppetmasdterd実行時に以下のように--reportsオプションで設定します。
$ sudo puppetmasterd --reports tagmail,log,rrdgraph,store
設定ファイルの場合、0.
reports = tagmail,log,rrdgraph,store
0.
[puppetmasterd]
    reports = tagmail,log,rrdgraph,store
0.
レポートの種類毎の解説
log
logはPuppetクライアントからのレポート通知をログファイルに出力します。puppetmasterdで--verboseオプションを指定している場合は、
Sep 16 19:57:12 puppet puppetmasterd[3077]: (//client.example.org/base/Package[ntpd]/ensure) change from absent to latest failed: Could not update: Could not find package ntpd at /etc/puppet/manifests/site.pp:9
Sep 16 19:57:12 puppet puppetmasterd[3077]: (//client.example.org/base/File[/etc/hosts]/mode) mode changed '600' to '644'
syslogのfacilityはデフォルトではdaemonですが、
[puppetmasterd]
    syslogfacility = local0
tagmail
tagmailはPuppetからのレポート通知をメール送信します。メールの内容は以下のようになっています。
Subject: Puppet Report for client.example.org From: report@puppet.example.org Sun Sep 16 20:01:06 +0900 2007 //client.example.org/base/Package[ntpd]/ensure (err): change from absent to latest failed: Could not update: Could not find package ntpd at /etc/puppet/manifests/site.pp:9 Sun Sep 16 20:01:06 +0900 2007 //client.example.org/base/File[/etc/hosts]/mode (notice): mode changed '600' to '644'
tagmailを利用する際には、
all:  root@localhost
mail: postmaster@domain.com
sun:  solarisadmins@domain.com
tagmailはその名の通り、
また、
[puppetmasterd]
    sendmail   = /usr/lib/sendmail
    reportfrom = puppet@localhost
    smtpserver = localhost
rrdgraph
rrdgraphは、
rrdgraphを利用するためには、
HTMLと画像ファイルは、
store
storeはrrdgraphで得られる情報と同じものを、
$ ls /var/puppet/reports/client.example.org/ 200709140455.yaml 200709160621.yaml 200709160625.yaml 200709161119.yaml 200709160618.yaml 200709160622.yaml 200709161038.yaml
レポートファイルの内容は次のようになります。
--- !ruby/object:Puppet::Transaction::Report
host: client.example.org
logs: []
metrics:
  time: !ruby/object:Puppet::Util::Metric
    label: Time
    name: time
    values:
    - - :file
      - File
      - 0.00976777076721191
    - - :total
      - Total
      - 1.16076874732971
    - - :config_retrieval
      - Config retrieval
      - 1.1510009765625
  resources: !ruby/object:Puppet::Util::Metric
    label: Resources
    name: resources
    values:
    - - :restarted
      - Restarted
      - 0
    - - :applied
      - Applied
      - 0
    - - :total
      - Total
      - 3
    - - :failed_restarts
      - Failed restarts
      - 0
    - - :skipped
      - Skipped
      - 0
    - - :failed
      - Failed
      - 0
    - - :scheduled
      - Scheduled
      - 2
    - - :out_of_sync
      - Out of sync
      - 0
  changes: !ruby/object:Puppet::Util::Metric
    label: Changes
    name: changes
    values:
    - - :total
      - Total
      - 0
records: {}
time: 2007-09-14 14:35:00.834810 +09:00   
実践テクニックは更に次回に続きます。
お知らせ
本連載をベースに、大幅に加筆/修正した形で、Software Design 2007年12月号にPuppet特集を寄稿いたしましたので、
