Closed evsheffield closed 8 years ago
@evsheffield Thanks for you PR. I understand you rightly removed the trailing whitespace and added "," to comply with puppet styling guidelines. What does the "$onlyif" gain?
Hi @davidl-zend. Based on my understanding of the zsmanage
resource, it seems that it does not guarantee idempotency implicitly as it is basically just a wrapper for exec
. This is fine for many commands, but some such as vhost-add
will fail on subsequent applications (e.g. because the vhost already exists). In order to prevent this failure, I thought it would be helpful to be able to specify an onlyif
to prevent it from being applied if it would result in an error. Although not a part of this PR, support for unless
could also be added, although the two accomplish the same goal. For example, I would like to test that the vhost I'm trying to add does not already exist, and prevent the command from happening if it does.
zendserver::zsmanage {'add vhost':
command => 'vhost-add',
zskey => $::zend_api_key_name,
zssecret => $::zend_api_key_hash,
additional_options => "-n ${app_name} -p 80 -t '${vhost_template}'",
onlyif => '/usr/bin/test ! -f /usr/local/zend/etc/sites.d/vhost_http_mysite.com_80.conf',
}
So as I understand the $onlyif allows you to specify your own tests.
@davidl-zend Thanks for the merge! Yes, that's correct. It basically just passes the value you specify directly through to exec
's onlyif
attribute.
Since the zsmanage resource executes commands that can fail on subsequent applys (e.g. adding a vhost), it's useful to have the
onlyif
attribute as a way of maintaining idempotence.