Puppet の実行時にメッセージと変数を出力したいと考えています。役立つかもしれないが実際には使用できない機能が 2 つあります。私のsite.pp
ファイル:
info "running site.pp info"
debug "running site.pp debug"
クライアントで実行すると:
puppet -t
私はそれらのプリントを取得しません。
Puppet の実行時にメッセージと変数を出力したいと考えています。役立つかもしれないが実際には使用できない機能が 2 つあります。私のsite.pp
ファイル:
info "running site.pp info"
debug "running site.pp debug"
クライアントで実行すると:
puppet -t
私はそれらのプリントを取得しません。
以下は、利用可能なすべての puppet ログ関数を含む puppet スクリプトです。
node default {
notice("try to run this script with -v and -d to see difference between log levels")
notice("function documentation is available here: http://docs.puppetlabs.com/references/latest/function.html")
notice("--------------------------------------------------------------------------")
debug("this is debug. visible only with -d or --debug")
info("this is info. visible only with -v or --verbose or -d or --debug")
alert("this is alert. always visible")
crit("this is crit. always visible")
emerg("this is emerg. always visible")
err("this is err. always visible")
warning("and this is warning. always visible")
notice("this is notice. always visible")
#fail will break execution
fail("this is fail. always visible. fail will break execution process")
}
スクリプト出力 (puppet 2.7):
注意: puppet 3.x の色は変更される場合があります (すべてのエラーは赤で表示されます)。
Puppet 関数のドキュメントから
info: Log a message on the server at level info.
debug: Log a message on the server at level debug.
情報/デバッグ メッセージを見つけるには、puppetmaster ログファイルを調べる必要があります。
あなたは使用することができます
notify{"The value is: ${yourvar}": }
パペットクライアントへの出力を生成する
情報、デバッグ、エラー、警告、アラート、重大および緊急メッセージなど、さまざまなタイプのメッセージでユーザーに通知する場合は、puppet リソースで「loglevel」メタパラメーターを使用します。
loglevel を使用すると、さまざまな種類のエラー メッセージに同じリソースを使用できます。
たとえば、デバッグメッセージを生成するために、次のように使用できます。
notify {"debug message":
loglevel => debug,
}
別の方法として、execs の使用を検討することもできます... (ただし、お勧めしません)
exec { 'this will output stuff':
path => '/bin',
command => 'echo Hello World!',
logoutput => true,
}
したがって、パペットを実行すると、次のような出力が得られるはずです。
notice: /Stage[main]//Exec[this will output stuff]/returns: Hello World!
notice: /Stage[main]//Exec[this will output stuff]/returns: executed successfully
notice: Finished catalog run in 0.08 seconds
ログ出力される最初の行。
このようにクライアントを実行できます...
puppet agent --test --debug --noop
そのコマンドを使用すると、取得できるすべての出力を取得できます。
puppet エージェントのヘルプの抜粋* --test:
Enable the most common options used for testing. These are 'onetime',
'verbose', 'ignorecache', 'no-daemonize', 'no-usecacheonfailure',
'detailed-exitcodes', 'no-splay', and 'show_diff'.
注:スイッチ--verbose
を使用するときに含める必要はありません。--test|-t
--verbose
それは私のために仕事をします。私はそれを使用して変数をチェックし、通知を表示します..
notify {"hello world $var1":}
Puppet の Web サイトにもドキュメントがあります: http://docs.puppetlabs.com/learning/ordering.html#notify-and-subscribe
より簡単な方法は、通知を使用します。例: notice("foo.pp works") または notice($foo)
サンプルにあるものを試しましたか。私はこれに不慣れですが、コマンドは次のとおりです:puppet --test --trace --debug。これが役立つことを願っています。