Last active
August 29, 2015 14:10
-
-
Save vinyar/8ec248c2207052a0f7dd to your computer and use it in GitHub Desktop.
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
powershell_script "Install IIS" do | |
code "add-windowsfeature Web-Server" | |
action :run | |
end | |
service "w3svc" do | |
action [:enable, :start ] | |
end | |
#node.default["iis_demo"]["indexfile"] = "Default2.htm" | |
#cookbook_file "c:\\inetpub\\wwwroot\\Default.htm" do | |
# source node["iis_demo"]["indexfile"] | |
# rights :read, "Everyone" | |
#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})){ | |
$NewWebsiteParams = @{Name= '#{site_name}' | |
Port= #{site_data["port"]} | |
PhysicalPath= '#{site_dir}' | |
ApplicationPool= '#{site_name}' | |
} | |
New-Website @NewWebsiteParams | |
} | |
elseif ((Get-WebBinding -Name #{site_name}).bindingInformation -ne '*:#{site_data["port"]}:') { | |
$CurrentBinding = (Get-WebBinding -Name #{site_name}).bindingInformation | |
$BindingParameters = @{Name= '#{site_name}' | |
Binding= $CurrentBinding | |
PropertyName= 'Port' | |
Value = #{site_data["port"]} | |
} | |
Set-WebBinding @BindingParameters | |
} | |
Get-Website -Name #{site_name} | Where {$_.state -like 'Stopped'} | Start-Website | |
EOH | |
end | |
template "#{site_dir}\\Default.htm" do | |
source "Default.htm.erb" | |
rights :read, "Everyone" | |
variables( | |
:site_name => site_name, | |
:port => site_data['port'] | |
) | |
notifies :restart, "service[w3svc]" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment