How Do You Write a Chef Recipe to Deploy a Apache Web Server to Linux Servers?

Problem scenario
You have Linux servers that need Apache web server installed on them.  How do you write a Chef recipe to deploy Apache web server?


This solution requires that the Chef server must have access to GitHub.  If you want to install Chef server, see this posting.  If you want to install Chef client, see this posting.  You will need Git installed on the Chef server too.

1. Go to the Chef server.  

2.  Go to the cookbooks directory (e.g., sudo find / -name knife.rb).  Find the "cookbook_path" stanza in this file.  If you need to create this file (e.g., you recently configured knife but did not create the path), do so now.  Then cd into it.

3.  Run this command:
git clone httpd

4.  From the Chef server if knife has been installed and you are not using the ChefDK, or from a workstation with knife and you are not using the ChefDK on the Chef server, run this command:

knife cookbook create httpd

Otherwise run this command:

chef generate cookbook httpd

5.  Run this command:

knife cookbook upload httpd

5. Do these steps:
    a) knife node edit <nameOfNode>  # Where "<nameOfNode>" is the FQDN of the Chef client server.
    b)  Under the run list, add no commas if it is currently empty, otherwise put a comma after the last (or single) recipe you find in the run list, then add this stanza:

    c)  Save the changes.

6.  You are done creating the recipe.  You can now run the Chef client.

Leave a comment

Your email address will not be published. Required fields are marked *