Tuesday, August 1, 2017

Knife commands

1)knife node-list    (list the nodes, that are on the chef-server).
2)knife node show turchin-vbox10   
Node Name:   turchin-vbox10
Environment: _default
FQDN:        
IP:          10.0.*********
Run List:    recipe[learn_chef_httpd]
Roles:       
Recipes:     learn_chef_httpd, learn_chef_httpd::default
Platform:    centos 7.2.1511
Tags:        

3)How to set the cookbook/recipe/role to the  run_list of the node?

knife node run_list set turchin-vbox10 chef-client
turchin-vbox10:
   run_list: recipe[chef-client]

(when you set it to the run_list,the existing cookbook in the run_list of the node, will get replaced with the new one).


How to create the role?

mkdir ~/learn-chef/roles


knife role from file roles/web.json   (to upload the role to the chef-server).
knife role list   ( list the number of roles).
knife role  show  web
chef_type:           role
default_attributes:
  chef_client:
    interval: 300
    splay:    60
description:         Web server role.
env_run_lists:
json_class:          Chef::Role
name:                web
override_attributes:
run_list:
  recipe[chef-client::default]
  recipe[chef-client::delete_validation]
  recipe[learn_chef_httpd::default]



once, you feel that Role is important ,you will set that role to the chef server.


How to clean up your environment?

In practice, use caution when using the --yes argument. The --yes argument suppresses any prompts for confirmation before performing a destructive operation.

delete your node from the chef-server:

knife node delete  turchin-vbox10   —yes
Deleted node[turchin-vbox10 ]

knife client delete node1-centos --yes
Deleted client[turchin-vbox10 ]

Chef makes a distinction between the nodes that are being managed and the clients that are authorized to make API calls to the Chef server. Therefore, you need to run knife node delete to remove the node's metadata from the Chef server and knife client delete to delete the entry (including the public part of the RSA key pair) from the Chef server's API client list.


Delete your cookbook from the Chef server

knife cookbook delete learn_chef_httpd --all --yes


Delete the role from the chef-server

knife role delete web --yes


Delete the RSA  private key from your node

During the bootstrap process, an RSA private key is generated on your node to enable your node to make API calls to the Chef server. The default location of this key is /etc/chef/client.pem on Linux systems.
If you plan to bootstrap your node a second time, for example, to practice the process, you'll need to log in to your node and delete the RSA private key file, like this.

sudo rm /etc/chef/client.pem


No comments:

Post a Comment