Accessing Knife via Ruby

Hey,

So I am writing a ruby script that will help with our deployments and as part of that I am leveraging the Chef REST API which is great but with some of that information I want to be able to pass that over to knife to do deletes. An example code is the following:

require 'chef/knife/ec2_server_delete’
delete_ec2 = Chef::knife::Ec2ServerDelete.new()
delete_ec2.name_args = node.ec2.instance_id
delete_ec2.run

This works but I get the following error:

ERROR: You did not provided a valid ‘AWS Access Key Id’ value.
ERROR: You did not provided a valid ‘AWS Secret Access Key’ value.

But both are set and work correctly from the command line. Also If I do this using the knife exec command it works. I assume I am missing something in my ruby but I am just pulling a blank and can’t seem to find any hints from looking at the chef/knife source code. Any pointers would be great.

Thanks
Zuhaib

On Dec 29, 2011, at 11:20 AM, Zuhaib Siddique wrote:

Hey,

So I am writing a ruby script that will help with our deployments and as part of that I am leveraging the Chef REST API which is great but with some of that information I want to be able to pass that over to knife to do deletes. An example code is the following:

require 'chef/knife/ec2_server_delete'
delete_ec2 = Chef::knife::Ec2ServerDelete.new()
delete_ec2.name_args = node.ec2.instance_id
delete_ec2.run

This works but I get the following error:

ERROR: You did not provided a valid 'AWS Access Key Id' value.
ERROR: You did not provided a valid 'AWS Secret Access Key' value.

But both are set and work correctly from the command line. Also If I do this using the knife exec command it works. I assume I am missing something in my ruby but I am just pulling a blank and can't seem to find any hints from looking at the chef/knife source code. Any pointers would be great.

There isn't really any reason to try and use Knife like this, just use Fog directly for a much better API.

--Noah

Noah,

True but I just want to simplify things by using knife and accessing the keys. I guess I could just load the knife.rb and parse out the information.

Zuhaib
On Dec 29, 2011, at 12:48 PM, Noah Kantrowitz wrote:

On Dec 29, 2011, at 11:20 AM, Zuhaib Siddique wrote:

Hey,

So I am writing a ruby script that will help with our deployments and as part of that I am leveraging the Chef REST API which is great but with some of that information I want to be able to pass that over to knife to do deletes. An example code is the following:

require 'chef/knife/ec2_server_delete'
delete_ec2 = Chef::knife::Ec2ServerDelete.new()
delete_ec2.name_args = node.ec2.instance_id
delete_ec2.run

This works but I get the following error:

ERROR: You did not provided a valid 'AWS Access Key Id' value.
ERROR: You did not provided a valid 'AWS Secret Access Key' value.

But both are set and work correctly from the command line. Also If I do this using the knife exec command it works. I assume I am missing something in my ruby but I am just pulling a blank and can't seem to find any hints from looking at the chef/knife source code. Any pointers would be great.

There isn't really any reason to try and use Knife like this, just use Fog directly for a much better API.

--Noah