Puppet 如果变量设置为undef,则定义的资源将失败

Puppet 如果变量设置为undef,则定义的资源将失败,puppet,Puppet,我正在编写一个木偶定义的类型,如下所示: 1 #--------------------------------------------------# 2 #-------------------WindowsLog---------------------# 3 #--------------------------------------------------# 4 # Type to set up a windows log #

我正在编写一个木偶定义的类型,如下所示:

  1 #--------------------------------------------------#
  2 #-------------------WindowsLog---------------------#
  3 #--------------------------------------------------#
  4 #           Type to set up a windows log           #
  5 #--------------------------------------------------#
  6
  7 define windows_log($size = '25MB', $overflowAction = 'OverwriteAsNeeded', $logName = $title)
  8 {
  9
 10     #Microsoft is stupid. Get-WinEvent has different names for logmode than limit-eventlog.
 11     #The following selector (basuically a ternary operator) should fix that
 12     $overflowWinEventName = $overflowAction ? {
 13         OverwriteAsNeeded   => "Circular",
 14         OverwriteOlder      => "AutoBackup",
 15         DoNotOverwrite      => "Retain",
 16         default             => undef,
 17     }
 18
 19     if($overflowWinEventName == undef)
 20     {
 21         fail("${$overflowAction} is not a valid overflow action")
 22     }
 23     else{
 24         exec { "Set maximum log size for ${logName}":
 25             provider => powershell,
 26             command  => "Limit-EventLog -LogName ${logName} -MaximumSize ${size} -OverflowAction ${overflowAction}",
 27             unless   => "\$log = Get-WinEvent -ListLog ${logName}; if(\$log.MaximumSizeInBytes -eq ${size} -and \$log.LogMode -eq '${overflowWinEventName}'){exit 0}else{exit 1}",
 28         }
 29     }
 30 }
但是,方法“fail”没有我想要的效果,并且在中列出的方法似乎都不正确

基本上,我试图让puppet只为这个特定的资源抛出一个错误,停止应用它,然后继续应用其他所有内容。Fail抛出一个解析器错误,它会杀死所有东西,而其他方法(warn、error等)似乎对代理没有影响


任何帮助都将不胜感激!我可能只是愚蠢地忽略了一些事情。

你的想法基本上是正确的。定义的资源不能像本机资源那样真正“失败”,但使用
if/else
构造,它只会在没有错误的情况下执行任何工作

只有在检测到可能导致整个目录无效的错误时,才使用
fail()。要仅向代理发送消息,请使用
notify
资源

notify {
    "FATAL - ${overflowAction} is not a valid overflow action":
        loglevel => 'err',
        withpath => true; # <- include the fully qualified resource name
}
通知{
“致命-${overflowAction}不是有效的溢出操作:”
日志级别=>'err',

withpath=>true;#我明白了,这是有道理的。我不知道我可以在notify上设置日志级别。你知道,我在回答这个问题之前也从未尝试过;-)