Chef CookBook to install and Configure Web Server on Linux?OS

Chef CookBook to install and Configure Web Server on Linux?OS

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 CookBook:

In the cookBook named webServer I have written configuration to install WebServer on Linux OS(RedHat or Ubuntu), and then create files for a httpd web server so that those files can be hosted on the WebServer.

Below is the 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 webServer inside the cookbook directory :

chef generate cookbook webServer        

  • Add "templates" directory to CookBook and add the "mycompany.html.erb" file:

mkdir webServer/templetes

vim mycompany.html.erb

# Add content to the file(link for GitHub repo will be shared for reference)        

  • Add "files" directory to CookBook and add the "webpage.html" file:

mkdir webServer/files

vim webpage.html

# Add content to the file(link for GitHub repo will be shared for reference)        

  • Create a recipe file inside the recipes folder of CookBook :

vim installapache.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,
-> sample.html file will be created
-> index.html file will be created using mycompany.html.erb template and variables will be passed for the file
-> webpage.html file will be created from the webpage.html file.        

Now our CookBook is ready to be deployed.

Once all the changes are ready just run the below command to deploy the CookBook

chef-client -z -o "recipe[webServer::installapache]"        

Once the above command successfully executes, we will have our WebServer deployed and one can test using the URL localhost:80/ followed by the file names.

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

Samarth Pant的更多文章

社区洞察

其他会员也浏览了