Skip to content

Instantly share code, notes, and snippets.

@mshock mshock/default.rb
Last active Aug 29, 2015

Embed
What would you like to do?
chef recipe for basic apache install
package "apache2" do
action :install
end
service "apache2" do
action [ :enable, :start ]
end
execute "mv /etc/apache2/sites-enabled/default-000.conf /etc/apache2/sites-available/default-000.conf.disabled" do
only_if do
File.exist?("/etc/apache2/sites-enabled/default-000.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
You can’t perform that action at this time.