Just in case anybody come across this post, I've used the following 
successfully:

require 'facter'
Facter.add('host_role') do
  setcode do
    location = case Facter.value(:hostname)
      when /home/ then $&
      else 'unknown'
      end
      Q%[This is a #{location} server]
  end
end

I'm sure this can be done more elegantly but for now, it will work.    

On Wednesday, September 3, 2014 2:40:13 PM UTC-7, Mike Reed wrote:
>
> Hello all,
>
> I'm looking to create a custom fact based on the result of a host name 
> prefix.  Some examples of host names are:
>
> home-server-01
> work-server-02
>
> I'd like the fact to assign a role to the server based on it's prefix and 
> I'm having a hard time getting this one to work:
>
> require 'facter'
> Facter.add('host_role') do
>     setcode do
>         hostname_array = Facter.value(:hostname).split('-')
>         first_in_array = hostname_array.first
>         first_in_array.each do |x|
>         if x =~ /^(home|work)/
>             role = '"#{x}" server'
>         else
>             role = 'other server'
>         end
>         role
>     end
> end
>
> Would anybody have an pointers on why this may not be working.  I feel 
> stupid for asking this but my understanding of ruby is quite basic and 
> google has stopped taking my calls.
>
> Thank you in advance for the help.
>
> Cheers,
>
> Mike
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/30e17909-fd00-4267-a628-663d8da5e391%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to