Last active
August 29, 2015 14:15
-
-
Save mshock/50877741a782b51d7b33 to your computer and use it in GitHub Desktop.
chef recipe for basic apache install
This file contains 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
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