Skip to content

Instantly share code, notes, and snippets.

@jtopjian
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save jtopjian/8799635 to your computer and use it in GitHub Desktop.

Select an option

Save jtopjian/8799635 to your computer and use it in GitHub Desktop.
require 'hiera'
class CapHiera
def self.hiera key, options = {}
scope = {}
if options[:host]
scope[:host] = options[:host]
scope[:role] = options[:host].roles.to_a
end
if options[:stage]
scope[:stage] = options[:stage]
else
scope[:stage] = fetch(:stage)
end
begin
@@h ||= Hiera.new({:config => './hiera/hiera.yaml'})
rescue Exception => e
STDERR.puts "Failed to start Hiera: #{e.class}: #{e}"
exit 1
end
@@h.lookup(key, 'nil', scope, order_override=nil, resolution_type=:priority)
end
def self.build_servers_from_stage stage
servers = CapHiera.hiera('servers', {:stage => stage})
servers.each do |k,v|
server k, v
end
end
end
require_relative 'lib/capistrano/cap_hiera'
CapHiera.build_servers_from_stage 'staging'
@jdowning
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment