WORKSTATION

$ vi cookbooks/apache/attributes/default.rb

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

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

 

$ vi cookbooks/apache/templates/default/index.html.erb

 

$ 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
template “/var/www/#{sitename}/index.html” do
source “index.html.erb”
mode “0644”
variables ({
:site_title=>data[“site_title”],
:tobewritten=>”To Be Written”
})
notifies :restart, “service[httpd]”
end
end
service “httpd” do
action [:enable, :start]
end
$ knife cookbook upload apache

CLIENT

Run convergence

$ chef-client

Add the addresses to the hosts file if not using dns

192.168.1.56 cc cc.localnet

192.168.1.56 vchefh1h.com vchefh1h

192.168.1.56 vchefh2h.com vchefh2h

Check the web pages

http://cc.localnet/

http://vchefh1h.com/

http://vchefh2h.com/