Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Chef Desktop is a deployment pattern which is used to automate desktop and laptop management with code. The desktop services target hard drive encryption, screensaver with a password, and many other basic functionalities. It is basically designed for administrators that have limited command-line or tools experience. In this blog, we will discuss the installation process for Chef Desktop.
Setup and Installation
The Chef workstation has everything that a user needs to get started with Chef. It ships with Chef Infra Client, Chef InSpec, Chef CLI, and many other user Chef tools.
Install Chef Workstation
Download the Chef Workstation on the system and then run the installer on the developer machine. Once downloaded, the user needs to run the installer, accept the default options, and wait while it completes.
The user can also verify the installation by running the below-mentioned command on the command line:
chef --version
The above command will list all of the Chef tools that have been installed.
Workstation Environment Setup
In order to store the configuration and keys, the user can create a .chef folder. By creating a .chef directory in the 'home' or 'root' folder makes these settings globally available. The user needs to navigate to the root directory and then create a .chef directory.
For Powershell:
Click on the Start and type Powershell in order to start the Powershell from the start menu.
Right-click on the Windows Powershell and select Run as Administrator.
The generated user and validator keys need to be transferred to the workstation in the .chef directory.
Set up Cookbook for Windows 10 and macOS platforms
This section introduces the user to the fundamentals of cookbook development and also walks the user through the process of creating, editing, and event testing a simple cookbook.
Developing Cookbooks
Testing is central to good software development. By testing the Chef Desktop cookbook, the user gets the opportunity to detect as well as correct problems before putting the changes into production. Testing saves money and time.
Setup the Development Environment
This step will help the user to prepare their workstation for developing, testing, and deploying the Chef Desktop cookbook.
Create your local repo
The user needs a local repository on their workstation in order to store cookbooks and related chef work and to share it with GitHub.
Use the below command from the command line in your root folder:
chef generate repo my_repo
Make Your First Cookbook
Create a cookbook
chef generate cookbook my_repo/cookbooks/my_cookbook
Make necessary changes in the metadata.rb file Using the Visual Studio Code, open the repo. The user needs to manage the metadata.rb file. The user then needs to add their contact information and also enter a starting version number for their cookbook.
Edit the default recipe. The user needs to open my_repo\cookbook\my_cookbook\recipes\default.rb in their Visual Studio and add:
Windows:
powershell_script 'get my path' do
code <<-CODE
[Environment]::GetEnvironmentVariable("Path")
CODE
end
macOS:
bash 'get my path' do
user 'root'
code <<-EOH
echo $PATH
EOH
end
Testing cookbooks with Test Kitchen
The Chef workstation installs the test kitchen. It also provides Chef Infra, which has a testing harness for cookbooks that uses VMs.
Test Kitchen Integrations
The test kitchen uses a driver plugin architecture to enable the Test kitchen to test the instances on cloud providers such as Amazon EC2, Google Compute Engine, and Microsoft Azure.
Run Test Kitchen
Run the virtual devices While working with the desktop cookbook that comes with the Chef, the user already has two virtual devices downloaded, also known as testing images. Now, use the below command to get them started:
kitchen create
Apply the Cookbooks to the images Run the below-mentioned command to apply the cookbooks with the base OS image:
kitchen converge
Verify the settings The user needs to make sure that the converged code is the code that the user meant to apply. In VSCode, navigate to the test\integration\default directory and examine the generated integration tests. The user must go through these tests carefully and make the necessary changes to match the setting to the changes in the default.rb file. Then run:
kitchen verify
If in case any of the test fails, then the user needs to check the output and compare the settings in mac.rb or windows.rb files against the matching tests.
Cleanup Once the user is done with testing, the user can run the below-mentioned command in order to delete the running test images:
kitchen destroy
Set up policy
Upload the Chef Desktop Cookbook
The user needs to upload their Chef Desktop Cookbook to their Chef Infra Server. The user needs to navigate to the /cookbooks from the development environment command line and then run:
knife cookbook upload <your cookbook name>
Since knife and many other Chef tools use the cookbook name that is specified either inside the metadata.rb file or the policyfile.rb file, which is case-sensitive.
Configure and upload the Policyfile to Chef Server
The user needs to check the Policyfile and then apply it to the test nodes. Policies are a convenient strategy for managing nodes.
Check the Policyfile
The user's Chef Desktop Policyfile.rb needs to look similar to:
name 'desktop-config-lite'
# default_source :supermarket, 'https://supermarket.chef.io' do |s|
# s.preferred_for 'chef-client'
# end
cookbook 'desktop-config-lite', '~> 1.2.6'
# run_list: chef-client will run these recipes in the order specified.
# cookbook::recipe
run_list 'desktop-config-lite::default'
# Specify a custom source for a single cookbook:
# cookbook 'custom-cookbook', '.'
This uses the desktop-config-lite cookbook from Chef Supermarket and run the default recipe.
Upload the Policyfile
The user needs to upload the Policyfile to the Chef Infra Server. The user needs to call the chef update in order to do some needed housekeeping around the policyfile.
If the user is using the Policyfile for the first time, then use the Chef install command to generate a lock file:
chef install Policyfile.rb
The user must run chef update and chef push every time the user needs to update the version of the cookbook:
chef update
chef push 'my_Policy_Group' 'Policyfile.rb'
Deploying Desktop Cookbook to a Node
Configure the node
Once the user has uploaded the policy to the server, the user is then ready to try the Chef Desktop cookbook on their first node. Before that, the user needs to:
Bootstrap the First Test Node
The user needs to create a client.rb.file that has the basic information required to connect to the Chef Infra Server instance.
Identify a 'test node'- a VM or laptop/desktop that the user can test their working cookbook against.
Get the serial number of the 'test node'
The user needs to configure the server and the client.rb file for their node from the workstation.
Install the Chef Infra Client
The user has to go to their test node and then install the Chef Infra Client from an elevated PowerShell window or by using the keyword sudo if working on macOS.
Once the Chef Infra Client is done with the installation, copy the client.rb file with the correct data for the node and Chef Infra server, and place that in c:\chef.
Load the Key
After that, copy the validator.pem file that the user has downloaded from the Chef Infra Server and place it in the same folder.
Set up a quick demo
This section will help the user set up a demonstration setup that the user can use to evaluate a trial version of the product.
Setting up the local system
There are some pre-written Terraform modules that the user can run on their system to create a demonstration setup on the AWS cloud, but for that, the user first needs to set up their local workstation.
Set up modules on the local system
The two ways through which the user can get the modules are:
Using this link, the user can directly get the modules
The user can clone the module from the public repository on GitHub.
If the user wants to get the modules from the public GitHub repository, then the user can simply run the below-mentioned command, provided that the git tool is already installed on the system.
After this, the user needs to install the tools which are required to support the modules:
Chef Workstation: it is required as it installs the chef tools that are necessary to create the chef-repo, install cookbooks, push the policies to the created server, as well as set up the local chef configuration.
Terraform: it is used to run the modules.
AWS CLI: it is required as the terraform needs this to communicate with the cloud provider.
PuTTy for Windows: it is required only when the system is running on windows, as the terraform modules use this to get keys from the server.
Setting up the cloud provider configuration in the system
The user needs to make sure that they are logged in through the command line tool for the cloud provider in order to create the instances in the cloud through terraform. In case of AWS, the user can simply install the AWS CLI and follow the login instructions.
Run the modules
After configuring the CLI, the user can navigate to the aws directory where the files for AWS are present. After that, rename the file terraform.tfvars.example to terraform.tfvars. Now the user is all set to run the following command that creates an Automate server and set up endpoints running Windows.
The command mentioned above will set up the server, create a chef-repo with the free version of the Chef Desktop cookbook, push the policy to the server, create a node and apply the policy to it and run the chef-client on it. Once it's done, the user can access the dashboard to see the report.
Frequently Asked Questions
Which command can be used to delete the running test images once the user has finished testing?
The 'kitchen destroy' command can be used to delete the running test images once the user has finished testing.
Mention the commands that must be run every time the user updates the cookbook's version.
The 'chef update' and 'chef push' commands must be run every time the user updates the cookbook's version.
What is the use of the client.rb file?
The client.rb file has the basic information which is needed to connect to the Chef Infra Server instance.
Conclusion
In this article, we have extensively discussed the Chef Desktop Installation.
If you wish to enhance your skills in Data Structures and Algorithms, Competitive Programming, JavaScript, etc., you should check out our Guided path column at Coding Ninjas Studio. We at Coding Ninjas Studio organize many contests in which you can participate. You can also prepare for the contests and test your coding skills by giving the mock test series available. In case you have just started the learning process, and your dream is to crack major tech giants like Amazon, Microsoft, etc., then you should check out the most frequently asked problems and the interview experiences of your seniors that will surely help you in landing a job in your dream company.