Fulfillment of an order for a dollhouse for optional classes

I am trying to solve the following problem with Puppet:

I have several nodes. Each node includes a set of classes. For example, there is a class mysqland webserver. node1 is only a web server, node2 is webserver + mysql.

I want to point out that IF a node has both webserver and mysql, mysql will install before the web server.

I cannot have a dependency Class[mysql] -> Class[webserver], since MySQL support is optional.

I tried using the steps, but they seem to inject dependencies between my classes, so if I have, for example, this:

Stage[db] -> Stage[web]
class {
'webserver': 
  stage => web ;
'mysql':
  stage => db ;
}

and I include the webserver class in my node

node node1 {
  include webserver
}

.. the mysql class is also included! This is not what I want.

How to determine the order on additional classes?

Edit: here is the solution:

class one {
    notify{'one':}
}

class two {
    notify{'two':}
}

stage { 'pre': }

Stage['pre'] -> Stage['main']

class {
    one: stage=>pre;
    # two: stage=>main; #### BROKEN - will introduce dependency even if two is not included!
}

# Solution - put the class in the stage only if it is defined
if defined(Class['two']) {
    class {
            two: stage=>main;
    } 
}

node default {
    include one
}

Result:

notice: one
notice: /Stage[pre]/One/Notify[one]/message: defined 'message' as 'one'
notice: Finished catalog run in 0.04 seconds

~

+5
1

[mysql] , , defined():

 if defined(Class['mysq'l]) {
   Class['mysql'] -> Class['webserver']
 }

, :

class optional {
    notify{'Applied optional':}
}

class afterwards {
    notify{'Applied afterwards':}
}

class another_optional {
    notify{'Applied test2':}
}

class testbed {

    if defined(Class['optional']) {
            notify{'You should see both notifications':}
            Class['optional'] -> Class['afterwards']
    }


    if defined(Class['another_optional']) {
            notify{'You should not see this':}
            Class['another_optional'] -> Class['afterwards']
    }
}

node default {
     include optional
     include afterwards
     include testbed
}

"puppet apply test.pp" :

notice: You should see both notifications
notice: /Stage[main]/Testbed/Notify[You should see both notifications]/message: defined 'message' as 'You should see both notifications'
notice: Applied optional
notice: /Stage[main]/Optional/Notify[Applied optional]/message: defined 'message' as 'Applied optional'
notice: Applied afterwards
notice: /Stage[main]/Afterwards/Notify[Applied afterwards]/message: defined 'message' as 'Applied afterwards'
notice: Finished catalog run in 0.06 seconds

2.7.1 Ubuntu 11.10

+5

All Articles