On Feb 22, 7:42 pm, Christopher Johnston <[email protected]> wrote:
> Anyone know of any issues in 2.7.9 when trying to use a regex pattern for
> matching a hostname?  If I specify the following below the client never
> loads the proper class, but if I put the fully qualified name in it works
> fine.
>
> Fails:
>
> node /somehost.*/ {
>   include some::class
> }
>
> Works:
>
> node /somehost.domain.com/ {
>   include some::class
> }


That's very surprising, especially since you are using regex in both
cases, and any string matched by the longer should also be matched by
the shorter.  Are you sure it's the shorter one that fails?  If it
were the longer, then that would make some sense because hostnames are
often taken as the *unqualified* names.

I'm not aware of any issues with node regexes, and I don't see any
open issues on that subject in the bug tracker.

It should be possible to strip this down to a very simple test case.
For example, make this your whole site.pp:
====
node /somehost.*/ {
  notify { 'node declaration': message => "short regex matches '$
{hostname}'" }
}

node /somehost.somedomain.com/ {
  notify { 'node declaration': message => "long regex matches '$
{hostname}'" }
}

node default {
  notify { 'node declaration': message => "no regex matches '$
{hostname}'" }
}
====

If the first regex matches then that node declaration will be used;
otherwise, if the second matches then that declaration will be used.
If neither regex matches then the default node declaration will be
used.  Putting all those in one place allows you to be certain that
the same hostname is being tested against each regex, and whichever
node declaration is used, the hostname that was tested will be
displayed in the client log.  If that doesn't give you enough to work
out the problem then please post the actual test manifest and the
resulting client log.

Some other things to consider:
1) if you plan to match against actual hostnames then regex is way
overkill.  Just use the appropriate hostnames themselves (preferrably
quoted).
2) the period is a regex metacharacter, so the difference between /
somehost.*/ and /somehost\..*/ may be important to you
3) node regexes are not automatically anchored to the beginning or end
of the hostname.  If you want that (and it looks like you probably do)
then you must put in the anchors yourself (e.g. /^somehost\..*$/).


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to