Hi guys, 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 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Mohit Chawla
2011-Apr-28 08:58 UTC
Re: [Puppet Users] Fetching the domain name from a string variable
On Thu, Apr 28, 2011 at 2:24 PM, Jan <jan@agetty.de> 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 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Jan
2011-Apr-28 11:44 UTC
Re: [Puppet Users] [SOLVED] Fetching the domain name from a string variable
On 04/28/2011 10:58 AM Mohit Chawla wrote:> On Thu, Apr 28, 2011 at 2:24 PM, Jan <jan@agetty.de> 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#splitI 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 puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Mohit Chawla
2011-Apr-28 12:23 UTC
Re: [Puppet Users] [SOLVED] Fetching the domain name from a string variable
On Thu, Apr 28, 2011 at 5:52 PM, Mohit Chawla <mohit.chawla.binary@gmail.com> wrote:> On Thu, Apr 28, 2011 at 5:14 PM, Jan <jan@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. :) > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.