Skip to content

Instantly share code, notes, and snippets.

@karmi
Created January 1, 2012 11:37
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karmi/1547103 to your computer and use it in GitHub Desktop.
Save karmi/1547103 to your computer and use it in GitHub Desktop.
Accessing knife.rb configuration from a Ruby script (eg. a Rakefile)
require 'fog'
require 'chef/config'
Chef::Config.from_file('./.chef/knife.rb')
EC2 = Fog::Compute.new provider: 'AWS',
region: Chef::Config[:knife][:region],
aws_access_key_id: Chef::Config[:knife][:aws_access_key_id],
aws_secret_access_key: Chef::Config[:knife][:aws_secret_access_key]
servers = EC2.servers.select { |s| s.tags["Name"] =~ /ec2\-test\-/ && s.state == "running" }
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment