Puppet : How to override / redefine outside child class (usecase and example detailled)
Posted
by alex8657
on Server Fault
See other posts from Server Fault
or by alex8657
Published on 2009-12-09T09:05:59Z
Indexed on
2010/04/30
8:27 UTC
Read the original article
Hit count: 297
puppet
|configuration-management
The use case i try to illustrate is when to declare some item (eq mysqld service) with a default configuration that could be included on every node (class stripdown in the example, for basenode), and still be able to override this same item in some specific class (eg mysql::server), to be included by specific nodes (eg myserver.local)
I illustrated this use case with the example below, where i want to disable mysql service on all nodes, but activate it on a specific node. But of course, Puppet parsing fails because the Service[mysql] is included twice. And of course, class mysql::server bears no relation to be a child of class stripdown
Is there a way to override the Service["mysql"], or mark it as the main one, or whatever ? I was thinking about the virtual items and the realize function, but it only permits apply an item multiple times, not to redefine or override.
# In stripdown.pp :
class stripdown {
service {"mysql": enable => "false", ensure => "stopped" }
}
# In mysql.pp :
class mysql::server {
service { mysqld:
enable => true,
ensure => running,
hasrestart => true,
hasstatus => true,
path => "/etc/init.d/mysql",
require => Package["mysql-server"],
}
}
# Then nodes in nodes.pp :
node basenode {
include stripdown
}
node myserver.local inherits basenode {
include mysql::server` # BOOM, fails here because of Service["mysql"] redefinition
}
© Server Fault or respective owner