WORKSTATION

$ cd cookbooks/apache/

$ cd attributes

$ vi cookbooks/apache/attributes/default.rb

default[“apache”][“sites”][“vchefh1h.com”] = { “port” => 80, “domain” => “vchefh1h.com” }
default[“apache”][“sites”][“vchefh2h.com”] = { “port” => 80, “domain” => “vchefh2h.com” }

 

$ vi cookbooks/apache/recipes/default.rb

#
# Cookbook Name:: apache
# Recipe:: default
#
# Copyright 2016, YOUR_COMPANY_NAME
#
# All rights reserved – Do Not Redistribute
#
package “httpd” do
action :install
end
node[“apache”][“sites”].each do |sitename, data|
document_root = “/var/www/#{sitename}”
directory document_root do
mode “0755”
recursive true
end
template “/etc/httpd/conf.d/#{sitename}.conf” do
source “vhost.erb”
mode “0644”
variables ({
:document_root=>document_root,
:port=>data[“port”],
:domain=>data[“domain”]
})
notifies :restart, “service[httpd]”
end
end
service “httpd” do
action [:enable, :start]
end

$ vi cookbooks/apache/templates/default/vhost.erb

ServerName

DocumentRoot

ServerAlias

$ knife cookbook upload apache

CLIENT

chef-client

$ cd /var/www/vchefh1h.com/

$ vi index.html

VCHEFH1H

VCHEFH1H

To Be Written

$ cd /var/www/vchefh2h.com/

$ vi index.html

VCHEFH2H

VCHEFH2H

To Be Written

 

Â