How to Install Chef in Ubuntu?
Chef refers to an open-source configuration management tool defining IT infrastructure as code. It automates deploying and managing software and systems across different environments.
Chef is composed of several vital components that work together to automate infrastructure and configuration management:
- Chef Server: Acts as the central hub that stores configuration data.
- Chef Workstation: This is where the developers create cookbooks and recipes. It is enhanced with tools like a command-line interface and a development kit to manage configurations and upload them to the Chef Server.
- Nodes: These are the servers or machines that are managed and configured using Chef. It communicates with the Chef Server to pull configuration details and modify them to maintain their desired state.
- Cookbooks: Cookbooks are a collection of recipes that define how a Chef should configure a node. They contain all the necessary code, scripts, and files to achieve a specific configuration or manage certain aspects of a system or application.
- Recipes: Recipes are the building blocks of cookbooks. They contain instructions written in a domain-specific language (DSL), also known as Ruby, that define the desired state of a specific aspect of a system, such as managing files or installing packages and configuring services.
Setting Up Chef Workstation in Ubuntu:
1. Download Chef Workstation: Refer to the chef.io document to install the version on your operating system
# sudo apt update
# sudo apt upgrade
2. Install Chef Workstation:
# sudo dpkg -i chef-workstation_21.10.640-1_amd64.de
# sudo apt-get install -f
3. Check Chef Version:
# /opt/chef-workstation/bin/chef -v
4. Create a Cookbook Directory:
# mkdir cookbooks
# cd cookbooks
1. Generate a New Cookbook:
# chef generates cookbook apache-cookbook
# ls
# tree
# sudo apt-get install tree
# tree
# cd apache-cookbook
2. Creating recipes inside cookbooks:
# chef generates recipe apache-recipe
# cd ..
# tree
# vi apache-cookbook/recipes/apache-recipe.rb
# chef exec ruby -c apache-cookbook/recipes/apache-recipe.rb
# chef-client -zr “recipe[apache-cookbook::apache-recipe]”
Register and get Auto Scalable instances with a Pay-As-You-Go Pricing Model!
3. Browse from your localhost which will provide you with the content.
- Updating recipe
# vi apache-cookbook/recipes/apache-recipe.rb
# chef exec ruby -c apache-cookbook/recipes/apache-recipe.rb
# chef-client -zr “recipe[apache-cookbook::apache-recipe]”