Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8092351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:15:56+00:00 2026-06-05T20:15:56+00:00

I am trying to solve the following problem with Puppet: I have multiple nodes.

  • 0

I am trying to solve the following problem with Puppet:

I have multiple nodes. Each node includes a collection of classes. For instance, there is a mysql class and webserver class. node1 is a webserver only, node2 is webserver + mysql.

I want to specify that IF a node has both webserver and mysql, the mysql install will happen before webserver.

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

I tried to use stages, but they seem to introduce dependencies between my classes, so if I have e.g. 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 gets included as well! That is not what I want.

How can I define order on optional 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

~

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:15:57+00:00Added an answer on June 5, 2026 at 8:15 pm

    If Class[mysql] is optional, then you can try checking if it exists with the defined() function:

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

    Here’s some sample code I used to test this out:

    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
    }
    

    After executing with a ‘puppet apply test.pp’, it generates this output:

    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
    

    I tested with puppet 2.7.1 on Ubuntu 11.10

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to solve the following problem. Lets say you have the the
I'm trying to solve the following problem: Say I have a Python script (let's
I have the following cyclic dependency problem I am trying to solve: typedef std::map<int,
I have the following problem which I'm trying to solve with javascript. I have
I'm trying to solve the following problem: I have a download button that when
Trying to solve this problem: I have the following set of divs that when
I need to solve the following problem: I have multiple rectangles of sizes: width
I'm trying to solve the following real-life problem you might have encountered yourselves: You
I'm trying to solve the following problem in Redis. I have a list that
I'm trying to solve the following problem: I have to images, one for normal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.