Ask Your Question

Revision history [back]

You would want to switch this around:

class myclass (
  $ldap_enable = $::myclass::params::ldap_enable
) inherits ::myclass::params {
  if $ldap_enable {
    $package = 'packageldap'
  } else {
    $package = 'packagestandard'
  }
}

class myclass::params {
  $ldap_enable = false
}

This would allow you to set ldap_enable at instantiation or via hiera or use the default of false. Unfortunately, the package evaluation is in the main class at this point. The only other way to go to keep it in params, would be to use one more level below params:

class myclass::params inherits ::myclass::globals {
  $ldap_enable = pick($::myclass::globals::ldap_enable, false)

  if $ldap_enable {
    $package = 'packageldap'
  } else {
    $package = 'packagestandard'
  }
}

class myclass::globals (
  $ldap_enable = undef
) {
  # Stub for more globals
}

Then you could just call package { $package: } in your main class that inherits params like I have listed above and remove the logic. If you wanted to override, you'd have to override myclass::globals::ldap_enable in hiera or via class instantiation like this:

class { '::myclass::globals':
  ldap_enable => true,
} ->
class { 'myclass': }

I think the globals scenario is far too complex for a single entry like this. If you had much more to derive logically BEFORE the params class point, then this would be the way to go.

Hopefully this helps.