Skip to content

Instantly share code, notes, and snippets.

@scarolan
Last active December 15, 2019 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save scarolan/6781185 to your computer and use it in GitHub Desktop.
Save scarolan/6781185 to your computer and use it in GitHub Desktop.
Refactored Apache default recipe for Chef Fundamentals Training - CentOS version
#
# Cookbook Name:: apache
# Recipe:: default
#
# Copyright 2013, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
package "httpd" do
action :install
end
service "httpd" do
action [ :enable, :start ]
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']
)
end
end
"iptables" do
action [ :stop, :disable ]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment