Skip to content

Instantly share code, notes, and snippets.

@burtlo
Last active August 29, 2015 14:24
Show Gist options
  • Save burtlo/b47c015dbd0dd98bb2e0 to your computer and use it in GitHub Desktop.
Save burtlo/b47c015dbd0dd98bb2e0 to your computer and use it in GitHub Desktop.
Refactored IIS
powershell_script "Install IIS" do
code "add-windowsfeature Web-Server"
action :run
end
service "w3svc" do
action [ :enable, :start ]
end
powershell_script "disable default site" do
code 'get-website "Default Web Site*" | where {$_.state -ne "Stopped"} | Stop-Website'
end
node["iis_demo"]["sites"].each do |site_name, site_data|
site_dir = "#{ENV['SYSTEMDRIVE']}\\inetpub\\wwwroot\\#{site_name}"
directory site_dir
powershell_script "create app pool for #{site_name}" do
code "New-WebAppPool #{site_name}"
not_if "C:\\Windows\\System32\\inetsrv\\appcmd.exe list appPool #{site_name}"
end
powershell_script "new website for #{site_name}" do
code <<-EOH
Import-Module WebAdministration
if(-not(test-path IIS:\\Sites\\#{site_name})){
New-WebSite -name #{site_name} -Port #{site_data["port"]} -PhysicalPath #{site_dir} -ApplicationPool #{site_name}
}
EOH
end
template "#{site_dir}\\Default.htm" do
source "Default.htm.erb"
rights :read, "Everyone"
variables(
:site_name => site_name,
:port => site_data["port"],
:ipaddres => node['ipaddress']
)
notifies :restart, "service[w3svc]"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment