Chef Installation Step by Step Guide
download chef server RPM
The above will configure chef server , generate base cookbooks, create SSL, give chef-server name wrt /etc/host entries
Now create admin and create pem
This will list the nodes registered with chef server
Bootstrap Chef client
download chef server RPM
Extract and Install using RPMwget https://packages.chef.io/stable/el/7/chef-server-core-12.8.0-1.el7.x86_64.rpmwget https://packages.chef.io/stable/el/7/chef-12.12.15-1.el7.x86_64.rpm
Edit your hostname inrpm -Uvh chef-11.16.2-1.el6.x86_64.rpmrpm -Uvh chef-12.12.15-1.el7.x86_64.rpm
Configure Chefvi /etc/hosts<IP ADDRESS> <HOSTNAME>
chef-ctl-reconfigure
The above will configure chef server , generate base cookbooks, create SSL, give chef-server name wrt /etc/host entries
Now create admin and create pem
Install gitchef-server-ctl user-create admin <name> <lastname> <email> <password> -f admin.pemchef-server-ctl org-create <create-org> <'orgname'> --association_user admin -f <orgname>.pem
Clone base repo from gityum install git -y
git clone https://github.com/chef/chef-repo.git
download and install chef developer kitVerify Chef serverwget https://packages.chef.io/stable/el/7/chefdk-0.15.16-1.el7.x86_64.rpmrpm -Uvh chefdk-0.15.16-1.el7.x86_64.rpm
chef verify
add bin to your profileCopy .pem files to chef repoecho 'eval "$(chef shell-init bash)"' >> ~/.bash_profilesource ~/.bash_profile
Configure your knifecp admin.pem <org>.pem ~/chef-repo/.chef/cp admin.pem <org>.pem /root/.chef/
[root@Chef-Server .chef]# vi knife.rbcurrent_dir = File.dirname(__FILE__)log_level :infolog_location STDOUTnode_name "admin"client_key "#{current_dir}/admin.pem"validation_client_name "<ORG VALIDATOR>"validation_key "#{current_dir}/<orgkey>.pem"chef_server_url "https://<Chef-server>/organizations/<organisatio>"syntax_check_cache_path "#{ENV['HOME']}/.chef/syntaxcache"cookbook_path ["#{current_dir}/../cookbooks"]wq!
cd ~/chef-repo
knife ssl fetch
knife client list
knife node list
Bootstrap Chef client
knife bootstrap NODENAME
It will run successful as no recipe / run list is added to host. export EDITOR=vi
knife node edit <NODENAME>
Now add the run list to newly added client and then run chef-client :) "recipe[name_of_recipe]"
##Run chef receipe from remote You could use knife ssh to run chef-client on all boxes that contain a certain role or recipe: knife ssh "role:web" "sudo chef-client" -x ubuntu --sudo Or if you're in EC2: knife ssh "role:web" "sudo chef-client" -x ubuntu -a ec2.public_hostname knife ssh name:mynode -a ipaddress -x ubuntu -i mycredentials.pem "sudo chef-client"You could use knife ssh to run chef-client on all boxes that contain a certain role or recipe: ##Bootstrap Remote node knife bootstrap new-host-ip -x root -P password -N node_name #To add a role or recipe to a node knife node run_list add node_name "recipe[cookbook::recipe]" knife node run_list add node_name "role[role_name]" knife node run_list add node_name "role[role_name],recipe[cookbook::recipe]"Chef- Knife commands cheat sheetknife commands:knife cookbook create apache — to create cookbookknife cookbook upload apache — to upload cookbook to chef-serverknife node run_list add NODENAME “recipe[NAME]” — to add receipe as a runlist to nodeknife node run_list add NODENAME -b “recipe[NAME]” “recipe[NAMEOFUPLOADING]” — to add a recipe before partcular recipe- useful comamnd to define the preecedence of recipes in a runlistknife -h == knife help commandknife node show NODENAME -a attribites(a-b-c-d)0- commanmd to show the attributes of the nodeknife search node “os:linux” — search for node which are linux nodesknife search node “os:linux” -a platform — search for niode which are linux nodes and shows playtformknife search node “os:linux” -a linux.model give me the result of linux as linux.model =ubuntu as outputchef-client — command to run on node called as convergence.knife environment list -w — to show all the enviromentknife environment compare devknife environment compare dev prod — compare environments between dev and prodknife environment compare — all -to compare all receipes in server across all environments.knife environment delete dev -to delete envknife environment show dev — shows environment information.kniofe role create role_name — command to create new roleknife role from file chef-repo/roles/rolename.rb — upload role(rolename.rb) to serverknife role list -w — list all roles in chef serverknife role delete role_name — delete the new roleknife node run_list add linuxnode “role[webserver]” — assign role(web server)to a node(linuxnode)As similar to roles — we use base role.create a base role — and we can use include that base role to all roles runlist. so if you need to update any roles with new runlist. All you need to change is the base role list.
Chef- Knife commands cheat sheet
knife commands:
knife cookbook create apache — to create cookbook
knife cookbook upload apache — to upload cookbook to chef-server
knife node run_list add NODENAME “recipe[NAME]” — to add receipe as a runlist to node
knife node run_list add NODENAME -b “recipe[NAME]” “recipe[NAMEOFUPLOADING]” — to add a recipe before partcular recipe- useful comamnd to define the preecedence of recipes in a runlist
knife -h == knife help command
knife node show NODENAME -a attribites(a-b-c-d)0- commanmd to show the attributes of the node
knife search node “os:linux” — search for node which are linux nodes
knife search node “os:linux” -a platform — search for niode which are linux nodes and shows playtform
knife search node “os:linux” -a linux.model give me the result of linux as linux.model =ubuntu as output
chef-client — command to run on node called as convergence.
knife environment list -w — to show all the enviroment
knife environment compare dev
knife environment compare dev prod — compare environments between dev and prod
knife environment compare — all -to compare all receipes in server across all environments.
knife environment delete dev -to delete env
knife environment show dev — shows environment information.
kniofe role create role_name — command to create new role
knife role from file chef-repo/roles/rolename.rb — upload role(rolename.rb) to server
knife role list -w — list all roles in chef server
knife role delete role_name — delete the new role
knife node run_list add linuxnode “role[webserver]” — assign role(web server)to a node(linuxnode)
As similar to roles — we use base role.
create a base role — and we can use include that base role to all roles runlist. so if you need to update any roles with new runlist. All you need to change is the base role list.
knife commands:
knife cookbook create apache — to create cookbook
knife cookbook upload apache — to upload cookbook to chef-server
knife node run_list add NODENAME “recipe[NAME]” — to add receipe as a runlist to node
knife node run_list add NODENAME -b “recipe[NAME]” “recipe[NAMEOFUPLOADING]” — to add a recipe before partcular recipe- useful comamnd to define the preecedence of recipes in a runlist
knife -h == knife help command
knife node show NODENAME -a attribites(a-b-c-d)0- commanmd to show the attributes of the node
knife search node “os:linux” — search for node which are linux nodes
knife search node “os:linux” -a platform — search for niode which are linux nodes and shows playtform
knife search node “os:linux” -a linux.model give me the result of linux as linux.model =ubuntu as output
chef-client — command to run on node called as convergence.
knife environment list -w — to show all the enviroment
knife environment compare dev
knife environment compare dev prod — compare environments between dev and prod
knife environment compare — all -to compare all receipes in server across all environments.
knife environment delete dev -to delete env
knife environment show dev — shows environment information.
kniofe role create role_name — command to create new role
knife role from file chef-repo/roles/rolename.rb — upload role(rolename.rb) to server
knife role list -w — list all roles in chef server
knife role delete role_name — delete the new role
knife node run_list add linuxnode “role[webserver]” — assign role(web server)to a node(linuxnode)
As similar to roles — we use base role.
create a base role — and we can use include that base role to all roles runlist. so if you need to update any roles with new runlist. All you need to change is the base role list.

No comments:
Post a Comment