Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 views
in Technique[技术] by (71.8m points)

knife - To setup chef workstation

Trying to setup chef workstation

knife configure -i

previous it worked but now its not working i am unable to create knife.rb it says the following error:

/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/lib/chef/config_fetcher.rb:53:in `realpath': Not a directory - /home/ubuntu/.chef/knife.rb (Errno::ENOTDIR)
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/lib/chef/config_fetcher.rb:53:in `realpath'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/lib/chef/config_fetcher.rb:53:in `config_missing?'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/lib/chef/knife.rb:350:in `block in locate_config_file'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/lib/chef/knife.rb:348:in `each'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/lib/chef/knife.rb:348:in `locate_config_file'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/lib/chef/knife.rb:418:in `configure_chef'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/lib/chef/knife/configure.rb:65:in `configure_chef'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/lib/chef/knife.rb:173:in `run'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/lib/chef/application/knife.rb:135:in `run'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/bin/knife:25:in `<top (required)>'
    from /usr/bin/knife:23:in `load'
    from /usr/bin/knife:23:in `<main>'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I suspect the ".chef" directory is missing. Try this:

mkdir ~/.chef

How I setup my chef workstation

First download the admin and validation keys from my chef server

ssh myusername@chefserver sudo cat /etc/chef-server/admin.pem          > ~/.chef/admin.pem
ssh myusername@chefserver sudo cat /etc/chef-server/chef-validator.pem > ~/.chef/chef-validator.pem

Reference these files when generating the ~/.chef/knife.rb file:

knife configure --server-url https://chefserver 
                --user admin 
                --key ~/.chef/admin.pem 
                --validation-client-name chef-validator 
                --validation-key ~/.chef/chef-validator.pem

Update: Chef server 12

Chef 12 no longer creates a default "admin" user. Instead you must create a user and associate it with an organisation.

Create a user called "myuser" and save the key:

ssh myusername@chefserver sudo chef-server-ctl user-create myuser myName mySurname [email protected] XXXXXX > ~/.chef/myuser.pem

Create an organisation called "demo" adding "myuser" as an admin and save the validator key:

ssh myusername@chefserver sudo chef-server-ctl org-create demo "Demo organisation" -a myuser > ~/.chef/demo-validator.pem

And generate the knife configuration file:

knife configure --server-url https://chefserver/organizations/demo 
                --validation-client-name demo-validator 
                --validation-key ~/.chef/demo-validator.pem 
                --user myuser 
                --key ~/.chef/myuser.pem 

Finally, Chef 12 respects SSL certs. The following command creates a trust relationship:

knife ssl fetch

Alternatively, you can disable SSL cert validation:

echo "ssl_verify_mode :verify_none" >> ~/.chef/knife.rb

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...