Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to configure Apache Virtual Hosts with Puppet and have been trying different things with little success.

I have defined a node as the following :

node 'test1.cob' inherits serveurClient {
        $smcvhost = 'all'
}

The serveurClient class includes the apache class. This works fine as Apache gets installed and all the configuration gets applied correctly, except the virtual hosts.

The configuration relating to the virtual hosts is the following :

class apache::config {
    File{
        require => Class["apache::install"],
        notify  => Class["apache::service"],
        ensure  => present,
        owner   => "www-data",
        group   => "www-data",
        mode    => 755
    }
    ...
    if ( $smcvhost == 'belleville' ) or ( $smcvhost == 'all' ) {
        apache::smcvhost{'belleville':
            client => 'belleville',
        }
    }
    ...
}

The apache::smcvhost definition works correctly because if I specify it directly in the node without the condition, the virtual host gets created correctly with no errors. If I remove the if statement, it will also get created correctly. I have tried only specifying the second condition but that did not make it work.

When this fails to be executed, I do not get any error. The puppet report just ignores this configuration part.

I am thinking that this is some sort of variable scoping problem but from what I have read, this practice seems correct and I imagine puppet would give me some error if I tried to evaluate a non-existing variable.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Puppet doesn't warn you on unset variables (except on templates, curiously enough), and, when you set a variable, only stuff specified after it is affected. So:

node 'test1.cob' inherits serveurClient {
        # Nothing above this line knows $smcvhost
        $smcvhost = 'all'
        # Stuff from this line until "}" knows $smcvhost
}
        # Stuff from this point on don't know $smcvhost

If you look at the release notes for recent versions of Puppet, you'll see that dynamic scoping is on its way to retirement. My advice is to avoid using variables to pass information as much as possible -- use parameters, such as in definitions or classes with parameters.

share|improve this answer
    
Thank you ! Too bad Puppet doesn't warn you... I'll find another way to do this then ! –  Antoine Benkemoun Aug 12 '11 at 14:53

Instead of:

node 'test1.cob' inherits serveurClient { $smcvhost = 'all' }

if you do:

node 'test1.cob' { $smcvhost = 'all' include serveurClient }

then your variable will exist in the serveurClient scope, which is where I assume your apache class is referenced.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.