- From: Daniel DeLeo <
>
- To:
- Subject: [chef] Re: Calling Chef::Knife::Ssh directly(?)
- Date: Wed, 1 Jun 2011 11:30:51 -0700
On Wednesday, June 1, 2011 at 10:29 AM, Miles, Ken wrote:
>
Folks,
>
>
I am investigating switching some of our Ruby scripts from using the
>
'system' function to calling the Chef libraries directly and am not
>
having much success. My latest error is:
>
>
/usr/lib/ruby/gems/1.8/gems/chef-0.9.8/lib/chef/rest/auth_credentials.rb:41:
>
in `signature_headers': Cannot sign the request without a client name,
>
check that :node_name is assigned (ArgumentError)
>
>
Below is a code snippet.
>
>
query = "role:#{role}"
>
knife_ssh = Chef::Knife::Ssh.new()
>
knife_ssh.config[:config_file] = conf_file
>
knife_ssh.config[:identity_file] = params["private_key"]
>
knife_ssh.config[:node_name] = ENV['HOSTNAME']
>
knife_ssh.config[:client_name] = ENV['HOSTNAME']
>
cmd_line = "hostname -f"
>
knife_ssh.name_args = [query, cmd_line]
>
sys_status = knife_ssh.run
>
The Chef::REST class that interacts with the API expects you to have
configured Chef::Config[:node_name] and Chef::Config[:client_key]. The
easiest way to accomplish this is to reuse the knife code to load your
configuration. After setting `Knife#config[:config_file]` you can call
`Knife#configure_chef` to load it.
As Bryan mentioned, you can skip a lot of boilerplate if you write your code
as `knife exec` scripts, or as a knife plugin. Take a look at this for more
info on knife plugins:
http://www.opscode.com/blog/2011/04/22/chef-0-10-preview-knife-plugins-and-ui/
--
Dan DeLeo
>
What am I doing wrong here?
>
>
Thanks,
>
>
Ken Miles
>
>
>
(mailto:
)
Archive powered by MHonArc 2.6.16.