title: How to deal with code duplication in puppet modules?
body: <p>I have implemented two puppet modules to setup and configure two components - A &amp; B. The directory structure of the modules folder looks like below:</p>
  
  <pre><code>modules
       modulea
            manifests
                 init.pp
                 install.pp
                 config.pp
                 service.pp
            templates
                 1.properties.erb (This one is also needed by moduleb)
                 2.properties.erb (This one is also needed by moduleb)
       moduleb
            manifests          
                 init.pp
                 install.pp
                 config.pp
                 service.pp 
            templates
                 1.properties.erb (same as in modulea)
                 2.properties.erb (same as in modulea) 
                 3.properties.erb
                 4.properties.erb
                 5.properties.erb
  </code></pre>
  
  <p>The code in install.pp and service.pp is identical in both the modules. The code in config.pp of modulea deals with 2 property files, while code in config.pp of moduleb deals with 5 property files. Out of these 5 property files, 2 property files are exactly same as modulea, while 3 property files are specific to moduleb. </p>
  
  <p>Pasted below is install.pp and service.pp code:</p>
  
  <pre><code>**init.pp of modulea**
  class modulea::install inherits modulea {
    package { $package_name: ensure =&gt; present }
  }
  
  **init.pp of moduleb**
  class moduleb::install inherits moduleb {
    package { $package_name: ensure =&gt; present }
  }
  
  **service.pp of modulea**
  class modulea::service inherits modulea {
    service { $service_name: ensure =&gt; running, }
  }
  
  **service.pp of moduleb**
  class moduleb::service inherits moduleb {
    service { $service_name: ensure =&gt; running, }
  }
  </code></pre>
  
  <p>What options do I have to reduce code duplication and improve the maintainability of code? What options do I have so that I can easily add one more module in future that has same pattern?</p>