48

Puppet の実行時にメッセージと変数を出力したいと考えています。役立つかもしれないが実際には使用できない機能が 2 つあります。私のsite.ppファイル:

info "running site.pp info"
debug "running site.pp debug"

クライアントで実行すると:

puppet -t

私はそれらのプリントを取得しません。

4

10 に答える 10

63

以下は、利用可能なすべての puppet ログ関数を含む puppet スクリプトです。

log_levels.pp

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 の色は変更される場合があります (すべてのエラーは赤で表示されます)。

于 2013-05-21T13:47:31.967 に答える
56

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}": }

パペットクライアントへの出力を生成する

于 2010-11-25T13:20:57.443 に答える
19

情報、デバッグ、エラー、警告、アラート、重大および緊急メッセージなど、さまざまなタイプのメッセージでユーザーに通知する場合は、puppet リソースで「loglevel」メタパラメーターを使用します。

loglevel を使用すると、さまざまな種類のエラー メッセージに同じリソースを使用できます。

たとえば、デバッグメッセージを生成するために、次のように使用できます。

 notify {"debug message":
      loglevel => debug,
    }
于 2013-10-04T10:23:17.067 に答える
12

別の方法として、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

ログ出力される最初の行。

于 2013-07-16T04:25:55.113 に答える
9

このようにクライアントを実行できます...

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

于 2013-05-19T08:52:52.333 に答える
6

それは私のために仕事をします。私はそれを使用して変数をチェックし、通知を表示します..

notify {"hello world $var1":}

Puppet の Web サイトにもドキュメントがあります: http://docs.puppetlabs.com/learning/ordering.html#notify-and-subscribe

于 2014-04-24T23:39:59.743 に答える
2

より簡単な方法は、通知を使用します。例: notice("foo.pp works") または notice($foo)

于 2014-01-30T17:49:49.680 に答える
0

サンプルにあるものを試しましたか。私はこれに不慣れですが、コマンドは次のとおりです:puppet --test --trace --debug。これが役立つことを願っています。

于 2011-05-04T05:45:14.337 に答える