如何将处理程序添加到puppet中定义的types? 例如,如果我有:
define foo::bar ($baz) { ... }
我如何在foo::bar中处理处理包含的东西
... notify => Foo::Bar['zippidy'] ...
?
处理程序会在接收到通知时在条件逻辑内运行各种Execs。
您可以通知您已在目录中的其他位置声明的已定义资源。 举个例子呢?
CentOS系统,httpd安装和停止。 testing与木偶2.7.18
$ service httpd status
httpd停止
以下是一个示例清单,其中包含已定义资源types内的exec资源,已定义资源types的声明和通知已定义资源types的服务资源。
./notify_defined_types.pp
define foo(){ exec { "${name}_exec": command => "echo hello ${name}", path => '/bin:/usr/bin', refreshonly => true, logoutput => true, } } foo { 'bar': } service { 'httpd': ensure => running, notify => Foo['bar'], }
当我应用这个时,在我的httpd服务资源的状态改变触发到Foo ['bar']资源的通知。 此通知将应用于在foo定义的资源types内使用的任何服务或exec资源。
$ puppet apply notify_defined_types.pp notice: /Stage[main]//Service[httpd]/ensure: ensure changed 'stopped' to 'running' notice: /Stage[main]//Foo[bar]/Exec[bar_exec]/returns: hello bar notice: /Stage[main]//Foo[bar]/Exec[bar_exec]: Triggered 'refresh' from 1 events notice: Finished catalog run in 0.51 seconds $ puppet apply notify_defined_types.pp notice: Finished catalog run in 0.38 seconds
合理? 你只是简单地通知你声明的资源。 它将触发在定义的资源types内暴露的任何exec或服务资源。