Search code examples
dependenciespuppetcontain

Am I using puppet contain correctly?


I am trying to create a dependancy relationship so that the phpwebserver profile is run before the silex_api profile.

role:

class roles::dev{
    include profiles::phpwebserver
    include profiles::silex_api

    Class ['profiles::phpwebserver'] -> 
    Class ['profiles::silex_api']
}

silex_api profile:

class profiles::silex_api{

    class { '::silex' :
        package_version => '1.6.2',
    }


    class {'::composer' :
         command_name  => 'composer.phar',
         target_dir    => '/var',
         user          => 'root'
    }

    contain ::composer
    contain ::silex
}

phpwebserver profile:

class profiles::phpwebserver{

    class { '::apache': 
    default_vhost => false,
    conf_template => "apache/httpd.silex.conf.erb",
    service_name => "httpd",
    package_ensure => "2.2.15-39.el6", 
    service_enable => true,
    service_ensure => "running",
  }

  class {'::apache::mod::php':
    package_name => "php",
      path => "${::apache::params::lib_path}/libphp54-php5.so",
  }


  contain ::apache
  contain ::apache::mod::php
}

classes:

class silex{
class { 'silex::install': }
class { 'silex::service': } 
}

The phpwebserver profiles successfully runs first if I explicitly contain all classes inside silex_api as shown below:

class profiles::silex_api{          
    class { '::silex' :
        package_version => '1.6.2',
    }


    class {'::composer' :
         command_name  => 'composer.phar',
         target_dir    => '/var',
         user          => 'root'
    }

    contain ::composer
    contain ::silex::install
    contain ::silex::service

}

Now I need to contain all the subclasses which to me, doesn't seem right. Is there a better way of accomplishing this or is this the standard way to ensure dependancies are set?


Solution

  • I believe this is the correct way as per this article.

    Role:

    class roles::dev{
          include profiles::phpwebserver
          include profiles::silex_api
    
          Class ['profiles::phpwebserver'] -> 
          Class ['profiles::silex_api']
    }
    

    Profile:

    class profiles::silex_api{
    
          class { '::silex' :
                package_version => '1.6.2',
          }
    
          class {'::composer' :
                command_name  => 'composer.phar',
                target_dir    => '/var',
                user          => 'root'
          }
    
          contain ::composer
          contain ::silex
    
    }
    

    Module:

    class silex (
       $package_name = $::silex::params::silex_package_name,
       $package_version,
       $release_version = "1",
    ) inherits ::silex::params
    {
    
           class { 'silex::install' :
               package_name    => $package_name,
               package_version => $package_version,
               release_version => $release_version,
           }
    
           contain silex::install
           contain silex::config
    }