multiple class declarations from each()

asked 2015-02-19 08:47:55 -0600

robshep gravatar image

updated 2015-02-19 09:40:51 -0600

llowder gravatar image

Hi,

I have a manifest that looks up which webapp is to be installed on each node. I have a function which works this out - working OK - but when I come to iterate through I get duplicate class declatation errors

The manifest is show below.
The nw_webapp::instance manifest actually sets up the container or destroys it as required. But on the second iteration, the class nw_webapp::instance is declared again, even though the parameters are different How could this be re-written to work and be a better fit with puppet idioms

Thanks in advance. Rob

class nw_webapp ( $webappcodes ) 
{
   $webapps = hiera("webapps")

   $webapps.each |$webapp| 
   {          
        $install_on_host = should_install_webapp($webappcodes, $webapp['name'])

        if( $install_on_host ){
            class { 'nw_webapp::instance':
                 webapp => $webapp,
                 ensure => running
            }
        }
        else {
            class { 'nw_webapp::instance':
                 webapp => $webapp,
                 ensure => absent
            }
        }   
    } 
}
edit retag flag offensive close merge delete

Comments

Can you post a link to a pastebin of the nw_webapp::instance source code? It's possible that it should be rewritten as a defined type instead of a parameterized class. Remember the Puppet rule about declaring resources - they must have a unique combination of type & title in a node catalog.

GregLarkin gravatar imageGregLarkin ( 2015-02-19 10:50:19 -0600 )edit