L17 – Adding Platform Support
Two clients running different OS’s, Ubuntu and CentOS
Enable root login on all systems for bootstrap
Ubuntu:
vi /etc/sshd_config
enable root login
service ssh restart
$ knife bootstarp a.b.com -x root -P -N
$ knife node run_list add nodename “recipe[apache]”
$ knife node run_list add nodename -b “recipe[apache]” “recipe[security]”
Now we need to modify the recipes to work for ubunto and centos
vi cookbooks/apache/attributes/default.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”][“nodename3”] = { “site_title” => “SITE THREE”, “port” => 80, “domain” => “nodename3.domain.com” }
case node[“platform”]
when “centos”
default[“apache”][“package”] = “httpd”
when “ubuntu”
default[“apache”][“package”] = “apache2”
end
vi cookbooks/apache/recipes/default.rb
Â
# # Cookbook Name:: apache # Recipe:: default # # Copyright 2016, YOUR_COMPANY_NAME # # All rights reserved – Do Not Redistribute # if node[“platform”] == “ubuntu” execute “apt-get update -y” do end end package “apache2” do package_name node[“apache”][“package”] end node[“apache”][“sites”].each do |sitename, data| document_root = “/var/www/#{sitename}” directory document_root do mode “0755” recursive true 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” elsif node[“platform”] == “oracle” template_location = “/etc/httpd/conf.d/#{sitename}.conf” end template template_location 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 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 include_recipe “php::default”
Discussion ¬