我正在写一个木偶定义类型如下:
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 }
然而,该方法失败了#39;没有我想要的效果,http://docs.puppetlabs.com/references/latest/function.html中列出的方法似乎都没有。
基本上我试图让puppet仅针对此特定资源抛出错误,停止应用它,然后继续应用其他所有内容。失败抛出一个解析器错误,它会杀死所有东西,而其他方法(警告,错误等)似乎对代理没有任何影响。
任何帮助将不胜感激!我可能只是愚蠢地忽略了一些事情。
答案 0 :(得分:1)
你的构造基本上是健全的。定义的资源不能像本机资源那样真正“失败”,但使用if/else
构造,只有在没有错误的情况下它才会起作用。
仅当您检测到导致整个目录无效的错误时才使用fail()
。要仅向代理发送消息,请改用notify
资源。
notify {
"FATAL - ${overflowAction} is not a valid overflow action":
loglevel => 'err',
withpath => true; # <- include the fully qualified resource name
}