Using Template in Chef to create HomePage of WebServer

Using Template in Chef to create HomePage of WebServer

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:

No alt text provided for this image

Step by Step process to Generate and Configure the CookBook:

  • Create a cookbooks directory:

mkdir cookbooks        

  • Generate the CookBook named usingTemplatesInChef inside the cookbook directory :

chef generate cookbook usingTemplatesInChef        

  • Create template file(directory named template will get automatically created inside cookbook)

chef generate template cookbooks/usingTemplatesInChef index.html        

  • Add code to the index.html.erb file(GitHub repository link will be provided for the code)
  • Create a recipe named webserver.rb in the recipe folder:

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:

No alt text provided for this image

要查看或添加评论,请登录

Samarth Pant的更多文章

社区洞察

其他会员也浏览了