Add an ubuntu node to chef

$ knife bootstrap[ -x root -P PWD -N

$ knife node run_list add “recipe[apache]”

$ knife node runlist add unique node name> -b “recipe[apache]” “recipe[security]”

Modify Apache recipe for different OS

$ cd cookbooks/apache/attrributes

$vi defaults.rb

default[“apache”][“sites”][“nodename1”] = { “site_title” => “SITE ONE”, “port” => 80, “domain” => “nodename1.domain.com” }
default[“apache”][“sites”][“nodename2”] = { “site_title” => “SITE TWO”, “port” => 80, “domain” => “nodename2.domain.com” }
default[“apache”][“sites”][“anothernode”] = { “site_title” => “ANOTHERNODE”, “port” => 80, “domain” => “anothernode.domain.com” }
case node[“platform”]
when “centos”
default[“apache”][“package”] = ‘httpd”
when “ubuntu”
default[“apache”][“package”] = ‘hapache2″
end

 

$ cd cookbooks/apache/recipes

$vi defaults.rb

package “apache2” do
package_name node[“apache”][“package”]
end
if node[“platform”] == “ubuntu”
template_location = “/etc/apache2/sites-enabled/#{sitename}.conf”
elsif node[“platform”] == “centos”
template_location = “/etc/httpd/conf.d/#{sitename}.conf”
end
node[“apache”][“sites”].each do |sitename, data|
document_root = “/content/sites/#{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 
template “/content/sites/#{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
execute “rm /etc/httpd/conf.d/welcome.conf” do
only_if do
File.exist?(“/etc/httpd/conf.d/welcome.conf”)
end
notifies :restart, “service[httpd]”
end
execute “rm /etc/httpd/conf.d/README” do
only_if do
File.exist?(“/etc/httpd/conf.d/README”)
end
notifies :restart, “service[httpd]”
end
service “httpd” do
service_name node[“apache”][“package”]
action [:enable, :start]
end