今天puppet群有朋友问我,exec资源中的refresh和refreshonly的区别是什么
以下是执行"pi exec"看到的部分解释:
(pi命令是puppet information的缩写,puppet中自带的查询手册,类似man)
Note that if an ``exec`` receives an event from another resource,
it will get executed again (or execute the command specified in
``refresh``, if there is one).
it will get executed again (or execute the command specified in
``refresh``, if there is one).
- **refresh**
How to refresh this command. By default, the exec is just
called again when it receives an event from another resource,
but this parameter allows you to define a different command
for refreshing.
- **refreshonly**
The command should only be run as a
refresh mechanism for when a dependent object is changed. It only
makes sense to use this option when this command depends on some
other object; it is useful for triggering an action::
# Pull down the main aliases file
file { "/etc/aliases":
source => "puppet://server/module/aliases"
}
# Rebuild the database, but only when the file changes
exec { newaliases:
path => ["/usr/bin", "/usr/sbin"],
subscribe => File["/etc/aliases"],
refreshonly => true
}
Note that only ``subscribe`` and ``notify`` can trigger actions, not
``require``,
so it only makes sense to use ``refreshonly`` with ``subscribe`` or
``notify``. Valid values are ``true``, ``false``.
refresh可能不太好理解,但refreshonly在pi命令中解释的比较清楚
如果有其他资源调用exec的时候,exec会执行好几次,加上refresh后就只会执行一次了,refresh作用就是不管有通知没通知,有多少次通知,都只执行一次。
如果没有refreshonly时,即使没有事件通知它,exec也会执行
如果加上refreshonly时,exec仅在其他资源用notify或subscribe事件通知时才会执行。refreshonly作用是让exec只在通知时执行,如果被通知多次就执行多次。
所以refresh和refreshonly也可以同时使用。
转载于:https://blog.51cto.com/dywer/688808