Skip to content

Instantly share code, notes, and snippets.

@smalltown
Last active April 23, 2016 15:24
Show Gist options
  • Save smalltown/6400eb17f95f45025e67eff6f2400ff4 to your computer and use it in GitHub Desktop.
Save smalltown/6400eb17f95f45025e67eff6f2400ff4 to your computer and use it in GitHub Desktop.
#
# Cookbook Name:: apache
# Recipe:: default
#
# Copyright (c) 2016 The Authors, All Rights Reserved.
package "apache2" do
action :install
end
service "apache2" do
action [ :enable, :start ]
end
execute "rm -f /etc/apache2/sites-enabled/000-default.conf" do
only_if do
File.exist?("/etc/apache2/sites-enabled/000-default.conf")
end
notifies :restart, "service[apache2]"
end
# Iterate over the apache sites
node['apache']['sites'].each do |site_name, site_data|
# Set the document root
document_root = "/var/www/html/#{site_name}"
# Add a template for Apache virtual host configuration
template "/etc/apache2/sites-enabled/#{site_name}.conf" do
source "custom.erb"
mode "0644"
variables(
:document_root => document_root,
:port => site_data['port']
)
notifies :restart, "service[apache2]"
end
# Add a directory resource to create the document_root
directory document_root do
mode "0755"
recursive true
end
# Add a template resource for the virtual host's index.html
template "#{document_root}/index.html" do
source "index.html.erb"
mode "0644"
variables(
:site_name => site_name,
:port => site_data['port']
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment