Ask Your Question

Extending the functionality of an already existing module

asked 2016-09-02 02:20:04 -0500

IF, lets say one would want to create a new module and then a class within that module, but would also like to use a class from a module from puppet-forge . The goal is then; to create a new class which should extend the functionality of the puppet-forge/class . and to do soo one would need to provide maybe different parameters and would like to maybe change some resources and add some functionality . The puppet-forge/class is parametrized so inheriting this class is not an option . Is there any other solution that can be applied, other than, creating the whole thing again

edit retag flag offensive close merge delete


There is some form of inheritance that can be used, but unfortunately it's difficult to build modules in that way. It heavily favors using composition over inheritance. You may need to make a wrapper module that calls the parts you need from the other module, and performs it's own parts around it

DarylW gravatar imageDarylW ( 2016-09-02 08:59:15 -0500 )edit

If you don't need to modify what's in an existing class, but only want to add to it, as long as they don't specifically prevent you from calling it in a different module, you can call the internal classes directly.

DarylW gravatar imageDarylW ( 2016-09-02 09:00:23 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-09-05 18:13:18 -0500

This is the classic way:

class my_great_class (
    Boolean $x = true,
    Boolean $y = true,
) inherits my_great_class::params {
    # note: define Class['some_foreign_class'] once only (globally!)

    class { 'some_foreign_class':
        y => $y,

    # some functionality extensions
    # here to come

But: You can't access or modify resources declared by some_foreign_class. A module is meant to cover a coherent task. To avoid copying all some_foreign_class parameters, use the splat

PS: Consider contributing to the module you want to use [if it's reasonable].

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2016-09-02 02:20:04 -0500

Seen: 62 times

Last updated: Sep 05 '16