Using Template in Chef to create HomePage of WebServer
Samarth Pant
Information Technology Analyst @ TCS | Contextual Master | OpenTofu | Terraform |
About Chef:
Progress Chef (formerly Chef) is a configuration management tool written in Ruby and Erlang. It uses a pure-Ruby, domain-specific language (DSL) for writing system configuration “recipes”. Chef is used to streamline the task of configuring and maintaining a company’s servers and can integrate with cloud-based platforms such as Amazon EC2, Google Cloud Platform, Oracle Cloud, OpenStack, IBM Cloud, Microsoft Azure, and Rackspace to automatically provision and configure new machines. Chef contains solutions for both small and large scale.
About the CookBook:
In the CookBook named "usingTemplatesInChef" I have written configuration to install a WebServer, Create index.html file using an embedded ruby template, and then starting and enabling the webserver service. In this cookbook I have also used Ohai to display some of the system properties on the WebServer Home Page.
I have added only 3 system attributes in template file, feel free to modify it as per your need.
CookBook Structure:
Step by Step process to Generate and Configure the CookBook:
领英推荐
mkdir cookbooks
chef generate cookbook usingTemplatesInChef
chef generate template cookbooks/usingTemplatesInChef index.html
vim webserver.rb # (you can give any file name you want or can also use the default.rb file which is already present
# Add content to the file(Link for GitHub repo will be shared for reference)
# In this recipe:
->> webserver will be installed based on Linux Distribution,
->> service for http server will start,
->> a index.html file containing system info will be created from the index.html.erb template file
Once all the changes are ready just run the below command to deploy the CookBook:
chef-client -zo "recipe[usingTemplatesInChef::webserver.rb]"
Final Result: