1
我想在傀儡中使用一种语言模式,并且在解决如何实现它时遇到困难。比方说,我有一个参数化类:木偶变量不变性
class ntp (
$ensure = 'present',
$ntp_package_ensure = 'present',
$ntp_package_name = 'ntp',
$ntp_config_ensure = 'file',
$ntp_config_path = '/etc/ntp.conf',
$ntp_service_ensure = 'running',
$ntp_service_enable = true,
$ntp_service_name = 'ntpd',
) {
话,我真的很希望能够说:
if $ensure == 'absent' {
$ntp_package_ensure = 'absent',
$ntp_config_ensure = 'absent',
$ntp_service_ensure = 'stopped',
}
但由于傀儡变量(常量?)是不可变的我得到的语法错误。那么木偶是怎么做的呢?我现在可以看到的唯一解决方案是添加一个巨大的if语句,将代码划分为确保段和其他段。
所以应该''确保'参数否决任何用户通过'ntp_package_ensure'和朋友? –
在我非常有人气的演示场景中,它应该。 – AlexLordThorsen