RE: [Puppet Users] puppet facter variable substring

1,273 views
Skip to first unread message

Steven Nemetz

unread,
Oct 24, 2012, 11:58:05 AM10/24/12
to Puppet-Users Mailing List
You can use regex for that
 
Here is an piece of my code for doing that. In my case [environment, 1 letter][collo, 2 letters]
 
  if $hostname =~ /^(.)(..)/ {
    $global_env = $1
    $location = $2
  }

Steven

 

Date: Wed, 24 Oct 2012 07:14:50 -0700
From: paolo....@gmail.com
To: puppet...@googlegroups.com
Subject: [Puppet Users] puppet facter variable substring

Hi 

I have a serires of servers that their hostname (not FQDN) is built in the same manner [header, 3 letters][collo, 4 letters][environment, 3 letters][number, 4 digits]. 
There's no specific separator between each part of hostname. Is there way I can extract the collo part of the hostname in puppet? 



TIA 
Paolo 


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/M8d-zyzlHw8J.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Paolo

unread,
Oct 25, 2012, 4:13:04 AM10/25/12
to puppet...@googlegroups.com
Hi Steven 

Why the if statement? 



TIA 
Paolo 

Steven Nemetz

unread,
Oct 25, 2012, 8:00:18 AM10/25/12
to Puppet-Users Mailing List
Not sure if puppet will let you access regex without being in some type of test.
Also, just habit. I'm usually doing some validation in the regex.

In this case, I've moved validation to after this and have it validate against data in hiera. Hiera has a list of the valid data center codes.

Steven



Date: Thu, 25 Oct 2012 01:13:04 -0700
From: paolo....@gmail.com
To: puppet...@googlegroups.com
Subject: Re: [Puppet Users] puppet facter variable substring
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/Z5GXvX1kvW4J.
Reply all
Reply to author
Forward
0 new messages