Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…th a fallback.
  • Loading branch information...
commit 1db8d06b685a09290e33e8baad5fa40667c92e6c 1 parent b64942f
@specialunderwear authored
Showing with 26 additions and 0 deletions.
  1. +26 −0 lib/puppet/parser/functions/server_with_role.rb
View
26 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
Please sign in to comment.
Something went wrong with that request. Please try again.