This will not work as shown. First, the regex is no good, but also node matchers are based on certname
, which is the FQDN of the host. That's not to say you can't do it, but it would require some more work and it would require you do enter the realm of unsupported configuration. So, basically, you're on your own. This is what Puppet's documentation says:
Node statements match nodes by name. A node’s name is its unique identifier; by default, this is its certname
setting, which in turn defaults to the node’s fully qualified domain name.
Note on Non-Certname Node Names
Although it’s possible to set something other than the certname
as the node name (using either the node_name_fact or node_name_value setting), we don’t generally recommend it. It allows you to re-use one node certificate for many nodes, but it reduces security, makes it harder to reliably identify nodes, and can interfere with other features.
Setting a non-certname node name is not officially supported in Puppet Enterprise.
No Puppet version was specified, so my answer is based on the latest (5.3) as of writing.
Instead, why don't you use your default node definition and combine it with logic based on the value of $::network
?
node default {
case $::network {
/^(10\.10\.[0-10]\.[0-255]|192\.168\.2\.0)$/ : {
include ntp
include dhcp
include common
}
default: { include common }
}
}
This was tested by changing the includes to notices and changing network to $var and testing various values.
[aaron@localhost ~]$ cat network.pp
#$var='10.10.1.5'
$var='192.168.2.1'
case $var {
/^(10\.10\.[0-10]\.[0-255]|192\.168\.2\.0)$/ : {
notice('match')
}
default: { notice('default') }
}
[aaron@localhost ~]$ puppet apply network.pp
Notice: Scope(Class[main]): default
Notice: Compiled catalog for localhost.local in environment production
in 0.21 seconds
Notice: Applied catalog in 0.01 seconds
I included this so you get a good idea of how you can quickly see if something should work without spending effort deploying it to your Puppetmaster and testing with various hosts.