如何在运行Puppet客户端时打印一些东西?

Ift*_*Bar 47 puppet

我想在Puppet运行时打印出消息和变量.我看到有两个功能可能会有所帮助但却无法真正使用它们.我的site.pp档案:

info "running site.pp info"
debug "running site.pp debug"
Run Code Online (Sandbox Code Playgroud)

当我在客户端上运行时:

puppet -t
Run Code Online (Sandbox Code Playgroud)

我没有得到那些印刷品.

Ale*_*hin 57

这是具有所有可用木偶日志功能的木偶脚本.

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")

}
Run Code Online (Sandbox Code Playgroud)

脚本输出(在puppet 2.7上): 不同的日志级别颜色

注意:木偶3.x颜色可能会改变(所有错误都将以红色打印)!

  • 作为主/代理运行时,这些消息仅显示在puppet master上.例如/var/log/puppet/master.log所有puppet函数都在master上运行,而且只在master上运行. (6认同)

小智 52

来自Puppet功能文档

info: Log a message on the server at level info.
debug: Log a message on the server at level debug.
Run Code Online (Sandbox Code Playgroud)

您必须查看puppetmaster日志文件以查找您的信息/调试消息.

你可以用

notify{"The value is: ${yourvar}": }
Run Code Online (Sandbox Code Playgroud)

为你的木偶客户产生一些输出

  • 您还可以使用通知("消息")将消息打印到木偶主日志(位于木偶大师)上. (10认同)
  • notify() 的缺点是,在多次调用的已定义类型中使用它时会出现双重声明错误。notice() 在这种情况下有效。 (2认同)
  • 通知的一个非常重要的功能是您可以传递元变量“日志级别”。这意味着您可以确保您的消息也可以显示为警告或错误。`notify{'This is bad': loglevel => 'warning'}` (2认同)

Rah*_*are 16

如果您想通过信息,调试,错误,警告,警报,关键和紧急消息等不同类型的消息通知用户,请在puppet资源中使用"loglevel"元参数.

通过使用loglevel,您可以将相同的资源用于不同类型的错误消息.

例如,为了生成调试消息,您可以将其用作,

 notify {"debug message":
      loglevel => debug,
    }
Run Code Online (Sandbox Code Playgroud)


Sek*_*ekm 8

作为替代,您可以考虑使用高管......(我不推荐它)

exec { 'this will output stuff':
  path      => '/bin',
  command   => 'echo Hello World!',
  logoutput => true,
}
Run Code Online (Sandbox Code Playgroud)

所以当你运行puppet时你应该找到一些输出:

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
Run Code Online (Sandbox Code Playgroud)

第一行是记录输出.


小智 7

你可以像这样运行客户端......

puppet agent --test --debug --noop
Run Code Online (Sandbox Code Playgroud)

使用该命令,您可以获得所有输出.

摘录木偶代理帮助
* --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'.
Run Code Online (Sandbox Code Playgroud)

注意:--verbose当您使用--test|-t开关时,不需要包括它,它也意味着--verbose.


mat*_*ths 5

那为我完成了任务。我用它来检查变量并显示通知。

notify {"hello world $var1":}
Run Code Online (Sandbox Code Playgroud)

这也是Puppet网站上的文档:http : //docs.puppetlabs.com/learning/ordering.html#notify-and-subscribe