How to set variables with basenode (in nodes.pp)

puppet

I'm trying Puppet and it seems to be good.

My question is very easy but I can't answer.

I have a file "node.pp" :

node basenode {
         include "dns"
#        include "ntp"
}


node 'myserver.domain.com' inherits basenode {
        $type_server = "client"
        include "ntp"
}

I would like to declare my variable "$type_server" without to do declare "include ntp" on each server.
I would like "basenode" includes "ntp" and use the value of "$type_server" in the node of my server.

The variable is used in the manifests of NTP.

Thanks in advance.

Best Answer

Don't use variables -- as Shane said, variable scoping in Puppet is FUBAR, and trying to use it just causes pain, suffering, nausea, headaches, and probably heart disease.

Instead, use defined types. It's what they're designed for. So, instead of using classes and includes everywhere, use a defined type and pass it the data it needs:

define ntp_server($type_server) {
    # Do all the things you'd normally do, using $type_server as needed
}

node 'myserver.domain.com' {
    ntp_server { ntp:
        type_server => "client"
    }
}