On 04/28/2011 10:58 AM Mohit Chawla wrote:
> On Thu, Apr 28, 2011 at 2:24 PM, Jan <[email protected]> wrote:
>
>> 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)?
>>
>
> Directly use the domain fact from facter or:
> http://docs.puppetlabs.com/references/latest/function.html#split
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
--
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.