Chef is infrastructure automation tool which can be used to build infra as code. This is quite useful tool which lets you to do numerous tasks simultaneously on hundreds of servers with just few commands…e.g. configuring application , install packages, create users…etc and much more…
Here, we’ll see how to write cookbook to configure apache server on centos and upload the cookbook on “Chef Server”.
We will also learn how to bootstrap client server and configure apache on client server.
Pre-Requisites:
- You should have a chef account created(go to https://www.chef.io/ and sign up for the account if you don’t have it).
- You have already downloaded “Chef Starter kit” from chef website
- You have already installed “Chef development kit” on chef workstation
- latest version of chef Development Kit can be downloaded for centos7 from below url:
wget https://packages.chef.io/files/stable/chefdk/4.13.3/el/7/chefdk-4.13.3-1.el7.x86_64.rpm.
- Generate a apache cookbook:

2. Now you will see a directory called apache. Please go inside apache/recipes:

3. Open the default.rb file in your favourite test editor and update it with below contents:

4. Now cd to “apache” directory once again and create “files/default” directories. Chef will look for index.html in this location.

5. Create index.html with below contents:

6. Upload the cookbook to Chef Server using Knife utility:

7. Now visit the Chef server portal and you will see your cookbook listed there

8. Here you can see the content of your recipe:

Your cookbook is ready to use.
Bootstrapping chef client:
Bootstrapping chef client from chef workstation would install chef client package in the chef client server and also list the chef client in the chef server.
command:
knife bootstrap 192.168.33.21 — sudo -U vagrant -N chefnode1
where 192.168.33.21 is the client node ip (chefnode1) in our case.


You will see chef node entry similar to this in the chef server:

Now add the runlist “apache” to the chef client — “chefnode1” .
command: knife node run_list add chefnode1 “recipe[apache]”

Now go to the chef client — chefnode1 and run below command:

Verify that httpd is installed and running in the chefnode1:

Now open your browser and type the ip of chefnode1, you will see the “Hello World” webpage.

Well, you have just created a webpage.
Happy Learning !!!
I am a student of BAK College. The recent paper competition gave me a lot of headaches, and I checked a lot of information. Finally, after reading your article, it suddenly dawned on me that I can still have such an idea. grateful. But I still have some questions, hope you can help me.
I am a website designer. Recently, I am designing a website template about gate.io. The boss’s requirements are very strange, which makes me very difficult. I have consulted many websites, and later I discovered your blog, which is the style I hope to need. thank you very much. Would you allow me to use your blog style as a reference? thank you!
Thank you very much for sharing. Your article was very helpful for me to build a paper on gate.io. After reading your article, I think the idea is very good and the creative techniques are also very innovative. However, I have some different opinions, and I will continue to follow your reply.
thank you
thank you