popularity question answers views user  
1
how to use chef to build server through ruby code

Hi, I’m looking at chef for a new SaaS project and can see how to create a new server with knife. But is there a way to do this through ruby?

we have a ruby server that needs to periodically create new servers. While we can use the fog library to create the actual server on EC2, its not clear how to install the chef-client. knife can do this but its not clear that knife has an interface/api that ruby code can call. I guess my code could run knife as a shell command but I’m hoping for something a bit more elegant.

thanks in advance

more →
1 736  
1
Is there some way to specify ssh user in the knife.rb file itself rather than on the cmd line?

Based on what I see in the source (https://github.com/opscode/knife-ec2/blob/master/lib/chef/knife/ec2_server_create.rb) :

  option :ssh_user,
    :short => "-x USERNAME",
    :long => "--ssh-user USERNAME",
    :description => "The ssh username",
    :default => "root"
...
bootstrap.config[:ssh_user] = config[:ssh_user]

I can’t think of single way of specifying a value for ssh_user inside the knife.rb file and not on the command line. Am I right about this? Or can someone illuminate me with some syntax I’m missing? So far I used trial & error to test the following but they didn’t get picked up:

config[:ssh_user]             = "ec2-user"
ssh_user                      = "ec2-user"
more →
1 808  
1
Knife ssh not work when a node is not bootstrapped

I have a node which is registered to chef server when its first time run the chef-client, so I can see the node in the web interface.

But I can’t run knife ssh to it, return error

“Net::SSH::AuthenticationFailed”

So, in this case, what is the best way to copy the ssh key?

more →
1 490  
1
Call knife commands from a Ruby script without shelling out

(Also asked on StackOverflow.com)

I’ve inherited some shell scripts that are helpful for setting up our application environment using Chef and knife. That’s nice.

But what I’d really like to do is have the power and flexibility of a Ruby script to do the same thing.

If I shell out to knife I lose the real time output of the command.

It seems like I should be able to call all of knife’s functionality from within Ruby by including the ‘chef’ gem and maybe the ‘cloudstack-fog’ plug-in I use.

But I haven’t found any examples or API documentation. Trying to dig through the chef gem source is an exercise in frustration.

Shouldn’t I be able to do the equivalent of a knife cloudstack server create -E … etc. from a Ruby script?

more →
0 169  
1
knife bootstrap fails ssh authentication on centos 6

I am bootstrapping a vm using knife which works on CentOS 5.4 but fails on CentOS 6.2 when attempting to ssh onto the node with “ERROR: all authorization methods failed (tried publickey, password)”

I can ssh onto the vm, why can’t knife? Anyone else seen this issue?

knife cs server create test-centos-6 -N test-centos-6 -d chef-full -r “role[base],role[cs_server]” -x <user> -P <pword> —no-public-ip -T “CentOS 6.2 x64 LAMP Stack” -VV

Bootstrapping Chef on 10.110.66.244 DEBUG: Adding 10.110.66.244 DEBUG: establishing connection to 10.110.66.244:22 DEBUG: connection established INFO: negotiating protocol version DEBUG: remote is SSH-2.0-OpenSSH_5.3' DEBUG: local isSSH-2.0-Ruby/Net::SSH_2.2.2 x86_64-linux' DEBUG: read 784 bytes DEBUG: received packet nr 0 type 20 len 780 INFO: got KEXINIT from server INFO: sending KEXINIT DEBUG: queueing packet nr 0 type 20 len 556 DEBUG: sent 560 bytes INFO: negotiating algorithms DEBUG: negotiated: * kex: diffie-hellman-group-exchange-sha1 * host_key: ssh-rsa * encryption_server: aes128-cbc * encryption_client: aes128-cbc * hmac_client: hmac-sha1 * hmac_server: hmac-sha1 * compression_client: none * compression_server: none * language_client: * language_server: DEBUG: exchanging keys DEBUG: queueing packet nr 1 type 34 len 20 DEBUG: sent 24 bytes DEBUG: read 152 bytes DEBUG: received packet nr 1 type 31 len 148 DEBUG: queueing packet nr 2 type 32 len 140 DEBUG: sent 144 bytes DEBUG: read 720 bytes DEBUG: received packet nr 2 type 33 len 700 DEBUG: queueing packet nr 3 type 21 len 20 DEBUG: sent 24 bytes DEBUG: received packet nr 3 type 21 len 12 DEBUG: beginning authentication of `root' DEBUG: queueing packet nr 4 type 5 len 28 DEBUG: sent 52 bytes DEBUG: read 52 bytes DEBUG: received packet nr 4 type 6 len 28 DEBUG: trying publickey DEBUG: connecting to ssh-agent ERROR: could not connect to ssh-agent DEBUG: trying publickey (8b:b8:c2:ee:1e:56:cc:fc:ea:dc:e2:58:7d:00:e2:02) DEBUG: queueing packet nr 5 type 50 len 348 DEBUG: sent 372 bytes DEBUG: read 84 bytes DEBUG: received packet nr 5 type 51 len 60 DEBUG: allowed methods: publickey,gssapi-keyex,gssapi-with-mic,password DEBUG: trying password DEBUG: queueing packet nr 6 type 50 len 60 DEBUG: sent 84 bytes DEBUG: read 84 bytes DEBUG: received packet nr 6 type 51 len 60 DEBUG: allowed methods: publickey,gssapi-keyex,gssapi-with-mic,password DEBUG: password failed ERROR: all authorization methods failed (tried publickey, password)

more →
0 209  
1
knife command not working

hi , Knife command throwing error below . /usr/bin/knife:22:in `require': no such file to load — chef/application/knife (LoadError)

from /usr/bin/knife:22

How to solve this ?

more →
0 72  
0
How to execute a node' runlist?
  1. I have register a node using the knife bootstrap
  2. I have upload a cookbook to chef server using knife
  3. In the web UI, I have add the cookbook into the node’s runlist

But the problem is: How can I request the node to execute the runlist from the webUI? Seems there is no way to do so?

Also the knife command is not able to do that? http://wiki.opscode.com/display/chef/Managing+Nodes+With+Knife

Thanks.

more →
1 389  
0
Can't unzip cookbooks on Windows Command Line - 'tar' not recognized

Chef newbie

When I try

knife cookbook site install COOKBOOK  

I get an error. The file does not unzip and I am left with a .tar.gz file ONLY. Any ideas?

The error message:

STDERR: 'tar' is not recognized as an internal or external command, operable program or batch file.

Thanks in advance.

more →
0 124  
0
"knife prepare/cook" through ssh gateway

Hi, I try to cook via knife (solo) a server, which is only reachable through another one. <local machine> —> <ssh gateway/proxy/tunnel> —> <target server> It seems to be possible to configure a ssh gateway for bootstrapping but I couldn’t find an equivalent for “knife prepare” and “knife cook”. Is this supported/possible?

Cheers, derkaan

more →
0 73  
0
'knife openstack server create' failing

Hi.
I am trying to use the openstack plugin for knife, but am getting an error when trying to create a server. I’m new to setting this stuff up so any help gratefully appreciated.

The command I am running looks like this:

knife openstack server create -VV -N zkDNS -f 2 -x ubuntu -i ~/solartest.pem -S solartest -a 1.2.3.4 -I 7ae56480-1048-4093-b68e-f449d21020b4

The error I am getting is:

/usr/lib/ruby/gems/1.8/gems/knife-openstack-0.6.2/lib/chef/knife/openstack_server_create.rb:218:in `run': undefined method `push' for nil:NilClass (NoMethodError)
    from /usr/lib/ruby/gems/1.8/gems/fog-1.8.0/lib/fog/core/collection.rb:13:in `each'
    from /usr/lib/ruby/gems/1.8/gems/fog-1.8.0/lib/fog/core/collection.rb:13:in `each'
    from /usr/lib/ruby/gems/1.8/gems/knife-openstack-0.6.2/lib/chef/knife/openstack_server_create.rb:214:in `run'
    from /usr/lib/ruby/gems/1.8/gems/chef-10.16.2/lib/chef/knife.rb:408:in `run_with_pretty_exceptions'
    from /usr/lib/ruby/gems/1.8/gems/chef-10.16.2/lib/chef/knife.rb:168:in `run'
    from /usr/lib/ruby/gems/1.8/gems/chef-10.16.2/lib/chef/application/knife.rb:123:in `run'
    from /usr/lib/ruby/gems/1.8/gems/chef-10.16.2/bin/knife:25
    from /usr/bin/knife:19:in `load'
    from /usr/bin/knife:19

My knife.rb looks like this:

log_level                :info
log_location             STDOUT
node_name                'ubuntu'
client_key               '/home/ubuntu/.chef/ubuntu.pem'
validation_client_name   'chef-validator'
Validation_key           '/etc/chef/validation.pem'
chef_server_url          'http://my-chef-server:4000'
cache_type               'BasicFile'
cache_options( :path => '/home/ubuntu/.chef/checksums' )
cookbook_path [ '/home/ubuntu/chef-repo/cookbooks' ]
knife[:openstack_username] = "my username here"
knife[:openstack_password] = "my password here"
knife[:openstack_auth_url] = "http://my-horizon-ui:5000/v2.0/tokens"
knife[:openstack_tenant] = "solartest"

Running ‘knife client list’ returns ok so I think Chef workstation is setup correctly. Running ‘knife openstack server list’ returns ok so I think the knife-openstack plugin is setup correctly.

The versions I am using are: Chef: 10.16.2 knife-openstack: 0.6.2 Openstack: Essex

I have followed the chef workstation setup here: http://wiki.opscode.com/display/chef/Workstation+Setup+for+Debian+and+Ubuntu

I have also followed the openstack plugin instructions here: https://github.com/opscode/knife-openstack/blob/master/README.md

No amount of tweaking with the workstation setup or knife-openstack command params seems to make a difference.

Thanks in advance, Paul.

more →
2 171