Last active
August 29, 2015 13:57
-
-
Save scarolan/9695037 to your computer and use it in GitHub Desktop.
Apache Refactoring Bonus Exercise for Chef Fundamentals Training
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cookbook Name:: apache | |
# Recipe:: default | |
# | |
# Copyright 2013, YOUR_COMPANY_NAME | |
# | |
# All rights reserved - Do Not Redistribute | |
# | |
package "httpd" do | |
action :install | |
end | |
execute "mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bak" do | |
only_if do | |
File.exist?('/etc/httpd/conf.d/welcome.conf') | |
end | |
notifies :restart, "service[httpd]" | |
end | |
node['apache']['sites'].each do |site_name, site_data| | |
document_root = "/srv/apache/#{site_name}" | |
template "/etc/httpd/conf.d/#{site_name}.conf" do | |
source "custom.erb" | |
mode "0644" | |
variables( | |
:document_root => document_root, | |
:port => site_data['port'] | |
) | |
notifies :restart, "service[httpd]" | |
end | |
directory document_root do | |
mode "0755" | |
recursive true | |
end | |
template "#{document_root}/index.html" do | |
source "index.html.erb" | |
mode "0644" | |
variables( | |
:site_name => site_name, | |
:port => site_data['port'], | |
:image => site_data['image'] | |
) | |
end | |
end | |
service "httpd" do | |
action [ :enable, :start ] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default['apache']['sites']['clowns'] = { "port" => 80 , "image" => "http://clowns.jpg.to" } | |
default['apache']['sites']['bears'] = { "port" => 81 , "image" => "http://bears.jpg.to" } | |
default['apache']['sites']['ponies'] = { "port" => 83, "image" => "http://mylittlepony.jpg.to" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<h1>Welcome to <%= node['motd']['company'] -%></h1> | |
<h2>We love <%= @site_name %></h2> | |
<%= node["ipaddress"] %>:<%= @port %> | |
<center><img src="<%= @image %>"></center> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment