Skip to content

Instantly share code, notes, and snippets.

@jbouse
Created August 17, 2012 15:56
Show Gist options
  • Save jbouse/3380125 to your computer and use it in GitHub Desktop.
Save jbouse/3380125 to your computer and use it in GitHub Desktop.
Puppet parser function to return an array of AWS ElastiCache cluster nodes
require 'rubygems'
require 'fog'
module Puppet::Parser::Functions
newfunction(:ecGetMembers, :type => :rvalue) do |args|
raise(Puppet::ParseError, "ecGetMembers(): wrong number of arguments(#{args.length}; must be 1)") if args.size != 1
params = {}
params[:ecc] = args[0]
Fog.credentials_path = '/etc/puppet/fog_cred'
@ecc = Fog::AWS::Elasticache.new()
@ec = @ecc.clusters.get(params[:ecc])
nodes = Array.new
#check to see if the cluster is registered and ready
if @ec and @ec.ready?()
@ec.nodes.each { |n| nodes << "#{n['Address']}:#{n['Port']}" }
end
nodes
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment