前回に引き続き、
puppetrunの使い方
Puppetのデフォルトの動作は、
- Puppetクライアントが数百台あるいはそれ以上の規模になった場合に、
Puppetサーバへのアクセスが同時間帯に集中する恐れがある - 新しいマニフェストをとりあえず1台だけに適用してテストしてみたい、
といった場合でも、 全サーバに勝手に適用されてしまう恐れがある
この問題に対処するためには、
puppetrunはPuppet付属のコマンドラインツールで、
puppetrunを利用するためには、
事前に必要な設定
- Puppetサーバ側の設定
- Puppetサーバ側では特に設定の必要はありません。
- Puppetクライアント側の設定
- Puppetクライアント側では、
puppetrunを実行してpuppetdへ接続してくるホストに対し、 以下のように/etc/ puppet/ namespaceauth. confで、 アクセスの許可/拒否を設定します。 [puppetrunner] allow server.
example. org allow *.example. com deny *.example. net
puppetd/puppetmasterdの起動とpuppetrunの実行
- puppetdの起動
- Puppetクライアント側で以下のようにpuppetdを起動します。--listenオプションをつけることで、
puppetrunからの接続を受け付けます。--no-clientオプションをつけることで、 puppetrunから始動されない限り、 puppetmasterdに接続しに行かなくなります。 $ sudo puppetd --verbose --server server.
example. org --listen --no-client - puppetmasterdの起動
- Puppetサーバ側でpuppetmasterdを起動します。特別なオプションは必要ありません。
$ sudo puppetmasterd --verbose
- puppetrunの実行
- Puppetサーバ側でpuppetrunを実行します。特にエラーがなければ、
exit code 0と表示して終了します。 $ sudo puppetrun --host client.
example. org Triggering client. example. org client. example. org finished with exit code 0 Finished
puppetrunのオプション
puppetrunの代表的なオプションは以下の通りです。
オプション名 | 説明 | 利用例 |
---|---|---|
host | 始動する対象となるホスト。複数指定可。 | --host a. |
all | 管理対象のホストすべてを始動します。 | --all |
class | 特定のクラスをインクルードしているホストのみ始動します。 | --class web |
parallel | 同時に始動するホストの数。デフォルトは1。 | --parallel 5 |
tag | 特定のタグがついたリソースのみを適用する。 | --tag maintenance |
テンプレート
前回解説したファイルサーバ機能では、
テンプレートの利用例として、
まず、
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName <%= fqdn %>:80
ERBテンプレートファイルには、
テンプレートファイルが用意できたら、
file { '/etc/httpd/conf/httpd.conf':
content => template('etc/httpd/conf/httpd.conf'),
}
タグ
リソースのメタパラメータであるtagを利用することにより、
リソースにタグを指定するには、
file { '/etc/hosts':
owner => 'root',
group => 'root',
mode => 644,
tag => 'hosts',
}
file { '/etc/sudoers':
owner => 'root',
group => 'root',
mode => 440,
tag => 'sudoers',
}
そして、
# puppetdでのタグの指定
$ sudo puppetd --tags hosts,sudoers
# puppetrunでのタグの指定 パターン1
$sudo puppetrun --tag hosts,sudoers
# puppetrunでのタグの指定 パターン2
$sudo puppetrun --tag hosts --tag sudoers
また、
class ssh {
package { 'sshd': ensure => present }
service { 'sshd': ensure => running }
}
モジュール
モジュールとは、
モジュールのディレクトリ/ファイル構成は、
MODULE_PATH/
module_name/
README
manifests/
init.pp
templates/
files/
MODULE_
マニフェストからモジュールを呼び出すには、
import 'autofs' # MODULE_PATH/autofs/manifests/init.ppを呼び出す
import 'autofs/init.pp' # 上と同じ
import 'autofs/util/stuff.pp' # MODULE_PATH/autofs/manifests/util/stuff.ppを呼び出す
Puppet本家WikiのPuppet Modulesでは、
実践テクニックは更に次回に続きます。