Hi folks,

This is a "best practices" question as much as a technical one.

I am trying to redefine variables when I include a specific class. The
use case is installing php 5.3 on a few select centos 5 boxes while
keeping the default php 5.1 install on others. Here is the relevant part
of my apache module:

---------------------------------------------------------------------
class apache::php inherits apache::base {
  include apache::params

  package { 'php':
    name => $apache::params::php_package,
    ensure => installed,
    require => Package['httpd'],
    notify => Service['httpd'];
  'php-gd':
    name => $apache::params::php_gd_package,
    ensure => installed,
    require => Package['php'],
    notify => Service['httpd'];
  'php-imap':
    name => $apache::params::php_imap_package,
    ensure => installed,
    require => Package['php'],
    notify => Service['httpd'];
  'php-ldap':
    name => $apache::params::php_ldap_package,
    ensure => installed,
    require => Package['php'],
    notify => Service['httpd'];
  }
}

class apache::php53 inherits apache::php {
  # $os is defined in site.pp.
  if $::os == 'rhel5' {
    # Dirty hack. Yuck.
    exec { '/usr/bin/yum -y replace php --replace-with php53u':
      onlyif => '/bin/rpm -q php',
      # Class common::redhat::el::el5 installs yum-plugin-replace.
      require => Class['common::redhat::el::el5'],
      notify => Service['httpd'],
    }
  }
  else {
    warning 'Class apache::php53 should only ever be defined for RHEL5 and its 
clones.'
  }
}

class apache::params {
  case $::os {
    # .../...
    'rhel5': {
      $httpd_package = 'httpd'
      $httpd_service = 'httpd'
      $rootdir = '/var/www/html'
      if defined(Class['apache::php53']) {
        $php_package = 'php53u'
        $php_gd_package = 'php53u-gd'
        $php_imap_package = 'php53u-imap'
        $php_ldap_package = 'php53u-ldap'
      }
      else {
        $php_package = 'php'
        $php_gd_package = 'php-gd'
        $php_imap_package = 'php-imap'
        $php_ldap_package = 'php-ldap'
      }
    }
  }
}
---------------------------------------------------------------------

When I add the apache::php53 to my host (I use LDAP as a node classifier
if that matters), php and its extensions get upgraded to 5.3. However,
when I add a class that depends on apache::php53, the defined function
evaluates as false.

class wordpress {
  # apache::lamp includes apache::php
  include apache::lamp

  if $::os == 'rhel5' {
    include apache::php53
  }
  # .../...
}

I understand defined is quite unreliable. So I am wondering if there is
a better option (read a working one)?

Hardcoding the packages names in class apache::php53 is not enough as I
have a bunch of other classes installing additional PHP modules. I
suppose I could subclass them as well but things would probably get
quite messy quite fast.

Thanks,
-- 
Arnaud

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to