Permalink
Browse files

Added function to retrieve only 1 server from the pool, optionally wi…

…th a fallback.
  • Loading branch information...
1 parent b64942f commit 1db8d06b685a09290e33e8baad5fa40667c92e6c @specialunderwear committed Dec 3, 2012
Showing with 26 additions and 0 deletions.
  1. +26 −0 lib/puppet/parser/functions/server_with_role.rb
@@ -0,0 +1,26 @@
+begin
+ require 'puppet/util/log'
+
+ module Puppet::Parser::Functions
+ newfunction(:server_with_role,
+ :type => :rvalue,
+ :doc => "Return one server object with a certain role:
+
+ server_with_role('frontend', { fallback => 'somevalue' })
+ " ) do |args|
+ Puppet::Parser::Functions.autoloader.loadall
+
+ fallback = nil
+
+ if args.kind_of?(Array) and args.count > 1
+ fallback = args.pop
+ end
+
+ servers = servers_with_role(args)
+ servers.count ? servers : fallback
+ end
+ end
+
+rescue NameError, LoadError
+ # the puppet clients don't have any activerecord. see http://projects.puppetlabs.com/issues/12594
+end

0 comments on commit 1db8d06

Please sign in to comment.