Created
May 30, 2013 11:48
-
-
Save srinivasmohan/5677312 to your computer and use it in GitHub Desktop.
Pull config info for a script from a chef data bag (So your script runs via "knife exec" without embedding config info in it)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This is meant to be run via "knife exec scriptname.rb" | |
# | |
require 'fog' | |
#Make sure you have a data bag called admin/ec2creds containing values 'aws_access_key_id' and 'aws_secret_access_key' | |
#which point to your AWS access key and secret access key. | |
DBAG_NAME='admin' | |
DBAG_KEY='ec2creds' | |
#Pull AWS credentials from the databag 'admin' with key 'ec2creds' | |
aws=Chef::DataBagItem.load(DBAG_NAME,DBAG_KEY) | |
fogobj = Fog::Compute.new( | |
:provider => 'AWS', | |
:region => 'us-east-1', | |
:aws_access_key_id => aws['aws_access_key_id'], | |
:aws_secret_access_key => aws['aws_secret_access_key'] | |
) | |
#This script is just to illustrate how to pull values from a chef data bag into a local script | |
#All it does is to emulate the stock 'ec2-describe-regions' command. | |
fogobj.describe_regions.body['regionInfo'].each do |x| | |
puts "REGION #{x['regionName']} => #{x['regionEndpoint']}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment