Friday, October 3, 2014

Chef

Chef is a configuration management tool

Cookbook has recipes

a)chef generate cookbook webserver
The above command will generate a cookbook for webserver

b)chef-apply webserver.rb
In the above command webserver.rb is the recipe which has the instructions for the resource webserver
webserver, files, appservers , are all called resources

c) Install is a default action that comes with the package

for the following ruby script

package 'httpd'  # this will install the httpd package

The script can also be written as
package 'httpd' do
  action :install
end

# Here above , httpd is a resource , which is of the type package
I have explicitly mentioned to install.

d)  While starting up the httpd package and enabling it , we do the following

service 'httpd' do
   action [:start, :enable]
end

So , start and enable are the two actions , that are used in the httpd package.
The start and enable are mentioned in a list , because , it is how the ruby will read the actions.

e) Now , everything is setup
 We will now host a html page on the webserver
The webserver will parse the html page and display it

in the same page , i will write the html code

file  '/var/www/html/index.html' do
  content '
  
    

hello world

'
end


The above is the content of the html page , which will display the html page.

f) But the problem is that , the html page is also included in the webserver creation code ruby file
Now , we will specify a separate file for the html code and use it to host the html code

g) Now we will create a template
chef generate template learn_chef_httpd index.html

Now the index.html file will be create in the templates directory as below

cookbooks/cookbook_name/learn_chef_httpd/templates/default/index.html

The index.html will be an empty file though
Now moving forward , we see the following.

Now , we see that , the file index.html is ending with the name erb
Which means , the file can have place holders as follows










No comments: