I would to apply the roles/profiles pattern as explained by Craig Dunn and at URL https://docs.puppet.com/pe/2016.4/r_n_p_full_example.html to my modules built with the rules specified at https://docs.puppet.com/guides/module_guides/bgtm.html.
Following these rules, every component modules (like Apache, OpenLDAP) keep only init.pp class parametrized.
#
# Component classes.
#
class apache ($logfile = '.log', $backend = $::apache::params::backend) inherits ::apache::params {
#
# This is the unique parametrized class.
#
}
class apache::log inherits ::apache {
#
# This class inherits the params.
#
}
Well, I usually use Roles/Profiles classes (like profile::apache, profile::openldap) using include-like or resource-like declaration of the component classes.
If I use resource-like declaration in a parent profile class (like profile::apache), and I use inherited profile (like profile::apache::openssh or profile::apache::openldap) to apply new features, i need to override the parent definition of component, but with Puppet v4 I can't override the component class declared in the parent profile (Class[::apache] { backend => 'ldap' } ) or use resource collector (Class <| name=='::apache'|> { backend => 'ldap' }).
#
# Profile classes.
#
class profile::apache {
class { ::apache:
logfile => '.my_log',
}
}
class profile::apache::openldap inherits profile::apache {
include ::openldap
# Doesn't work with Puppet 4.
Class[::apache] {
backend => 'ldap'
}
#
# OR...
#
# Also, doesn't work with Puppet 4.
Class <| name=='::apache'|> {
backend => 'ldap'
}
}
In the past I used parametrized component classes and in the child profile classes I could call the component classes in the direct way without override the params of init.pp of component class.
This is my old approch:
class apache::backend ($backend) inherits ::apache {
#
# Do stuff.
#
}
class profile::apache::openldap inherits profile::apache {
include ::openldap
class { ::apache::backend:
backend => 'ldap'
}
}
class profile::apache::mysql inherits profile::apache {
include ::mysql
class { ::apache::backend:
backend => 'mysql'
}
}
So, with my new style of coding, how can I apply the roles/profile pattern if I use only init.pp component class parametrized?
Puppet DSL is not an object-oriented language in the sense you seem to think it is. In particular, class inheritance does not do what you think. The language specification remarks:
In practice, only the latter use of inheritance is common.
You are trying to modify class parameters of the parent class itself, which
Indeed, the language guide also says (emphasis added):
When you say ...
... I suppose you mean that you used resource-like class declarations, so as to specify parameter values in your manifests. That's poor style in most cases, with the exception being a class declaring private classes of the same module.
As the language guide says, by relying on external data lookup (i.e. Hiera) to customize module parameters. Note also that this applies to component modules, too. Given the existence of public class
apache::log
that inherits from classapache
, you should not declare the latter via the resource-like syntax.