Once the chef-workstation installation(here is the link to run the script to install chef-workstation on RHEL 7) is completed we need to verify the main components in the chef-dk
chef verify
To configure the environment variable use chef env
chef env
Chef gem: The chef gem subcommand is a wrapper around the gem command in RubyGems and is used by Chef to install RubyGems into the Chef development kit development environment. All knife plugins, drivers for Kitchen, and other Ruby applications that are not packaged within the Chef development kit will be installed to the .chefdk path in the home directory: ~/.chefdk/gem/ruby/ver.si.on/bin (where ver.si.on is the version of Ruby that is packaged within the Chef development kit).
Configure ruby path
echo 'export PATH="/opt/chefdk/embedded/bin:$PATH"' >> ~/.bash_profile && source ~/.bash_profile
To show an existing gem in the chef-dk
chef gem list chef-dk
Install a gem (knife-config)
chef gem install knife-config
View contents of gem
chef gem content knife-config
Generate app in chef: We can use 'chef generate app ' to generate a cookbook structure. This is build around with a idea of one repo for all cookbooks.
chef generate app chef-repo
Attribute: An attribute is a specific detail about a node. Attributes are used by the chef-client to understand:
The current state of the node
What the state of the node was at the end of the previous chef-client run
What the state of the node should be at the end of the current chef-client run
chef generate attribute /path/to/cookbook
Create a sample cookbooks in the chef-repo app
chef generate cookbook cookbooks/learnchef
Here 'cookbooks' (cookbooks/learnchef) is the folder where all the cookbooks are kept in the chef-repo app
.chef Directory Creation
.chef directory is used to store 3 files
--> knife.rb
--> organization-validator.pem
--> user.pem
Where ORGANIZATION and USER represent strings that are unique to each organization. These files must be present in the .chef directory in order for a workstation to be able to connect to a Chef server.
create a .chef directory
mkdir -p ~/chef-repo/.chef
Add .chef to the .gitignore file to prevent uploading the contents of the .chef folder to GitHub
echo .chef >> ~/chef-repo/.gitignore
Copy Oraganization-validator.pem and user.pem from chef-server to the .chef folder on your local machine.
scp -i /path/to/privatekey.pem user@<ip-address>:/path/to/Oraganization-validator.pem /some/local/directory
scp -i /path/to/privatekey.pem user@<ip-address>:/path/to/user.pem /some/local/directory
Knife --> knife runs from a management workstation and sits in-between a Chef server and an organization’s infrastructure. knife interacts with a Chef server by using the same REST API that is used by a chef-client. Role-based authentication controls (RBAC) can be used to authorize changes when knife is run with the Chef server. knife is configured during workstation setup, but subsequent modifications can be made using the knife.rb configuration file.
Create a knife.rb file.
knife configure /path/to/.chef
Enter the details as requested.
Enter Private DNS chef-server as chef_server_url
Fetch and validate the SSL certification from the chef server
knife ssl fetch
knife ssl check
Download a cookbook from github learn_chef_httpd
configure apache webserver
Double check the knife.rb file whether all the components are in place or else map them.
navigate to cookbooks folder
cd /path/to/chef-repo/cookbooks
Cloning cookbook from github
git clone https://github.com/learn-chef/learn_chef_httpd.git
Upload cookbook to the chef-server
knife cookbook upload learn_chef_httpd
To check the cookbook list in chef-server
knife cookbook list