is there a simple way to fetch the domain name (e.g. test-domain.tld) from
a string variable (e.g. host-internal.test-domain.tld)?
Jan
is there a simple way to fetch the domain name (e.g. test-domain.tld) from
a string variable (e.g. host-internal.test-domain.tld)?
I should have been more clear about what I'm trying to achieve. I'm not
talking about the domain name of a node but from a string contained
variable. Lets say we've got the following variable located somewhere in
our manifest ...
$vhost = "host-internal.test-domain.tld"
... and there might be a need to compare it with a string in order to
execute some peace of code:
if $vhostDomain == "test-domain.tld" {
# create file if $variable contains domain name
file { '/some/file': ensure => present }
}
Further more the $vhost variable is passed to a definition to create the
respective vhost. For the conditional to work the variable $vhostDomain
shall contain only the domain part of $vhost.
What about using regsubst here? I just played around with it a few times
but didn't
I think that the split function won't work because it splits the string
into three separate parts by using '.' as the delimiter and to join them
back together (domain part + tld) doesn't seem to be much practical.
Actually I solved my problem by using the "regsubst" function:
-------------------------->------------------------------
:~$ cat test.pp;
$vhost = "host-internal.test-domain.tld"
$vhostSplit = regsubst($vhost,'[a-z\-]*\.(.*)','\1')
alert $vhostSplit
:~$ puppet apply test.pp;
alert: Scope(Class[main]): test-domain.tld
--------------------------<------------------------------
Works like a charm, just what I was searching for ;)
Jan
On Thu, Apr 28, 2011 at 5:14 PM, Jan <j...@agetty.de> wrote:Works like a charm, just what I was searching for ;)
Heh, sorry for not understanding the problem correctly. Thanks for posting the solution. :)