From 285c6d759dcc353b953cf45be029ab4c338103a0 Mon Sep 17 00:00:00 2001 From: Drew Wilson Date: Fri, 7 Feb 2014 09:48:23 +0000 Subject: [PATCH] update website physicalPath and ApplicationPool for existing websites --- manifests/manage_site.pp | 23 ++++++++++++++++-- spec/defines/manage_site_spec.rb | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/manifests/manage_site.pp b/manifests/manage_site.pp index 0e436e7..153d138 100644 --- a/manifests/manage_site.pp +++ b/manifests/manage_site.pp @@ -7,7 +7,10 @@ if ($ensure in ['present','installed']) { iis::createpath { "${site_name}-${site_path}": site_path => $site_path - } + } + + $cmdSiteExists = "Test-Path \\\"IIS:\\Sites\\${site_name}\\\"" + $createSwitches = ["-Name \\\"${site_name}\\\"", "-Port ${port} -IP ${ip_address}", "-HostHeader \\\"${host_header}\\\"", @@ -19,10 +22,26 @@ exec { "CreateSite-${site_name}" : command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-WebSite ${switches} \"", path => "${iis::param::powershell::path};${::path}", - onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\${site_name}\\\")) { exit 1 } else { exit 0 }\"", + onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((${$cmdSiteExists})) { exit 1 } else { exit 0 }\"", logoutput => true, require => [ Iis::Createpath["${site_name}-${site_path}"], Iis::Manage_app_pool[$app_pool] ], } + + exec { "UpdateSite-PhysicalPath-${site_name}": + command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\${site_name}\\\" -Name physicalPath -Value \\\"${site_path}\\\"\"", + onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((${$cmdSiteExists}) -eq \$false) { exit 1 } if ((Get-ItemProperty \\\"IIS:\\Sites\\${site_name}\\\" physicalPath) -eq \\\"${site_path}\\\") { exit 1 } else { exit 0 }\"", + path => "${iis::param::powershell::path};${::path}", + logoutput => true, + before => Exec["CreateSite-${site_name}"], + } + + exec { "UpdateSite-ApplicationPool-${site_name}": + command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\${site_name}\\\" -Name applicationPool -Value \\\"${app_pool}\\\"\"", + onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((${$cmdSiteExists}) -eq \$false) { exit 1 } if((Get-ItemProperty \\\"IIS:\\Sites\\${site_name}\\\" applicationPool) -eq \\\"${app_pool}\\\") { exit 1 } else { exit 0 }\"", + path => "${iis::param::powershell::path};${::path}", + logoutput => true, + before => Exec["CreateSite-${site_name}"], + } } else { exec { "DeleteSite-${site_name}" : command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; Remove-WebSite -Name \\\"${site_name}\\\"\"", diff --git a/spec/defines/manage_site_spec.rb b/spec/defines/manage_site_spec.rb index 2e876e6..0aa09aa 100644 --- a/spec/defines/manage_site_spec.rb +++ b/spec/defines/manage_site_spec.rb @@ -17,6 +17,16 @@ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} + + it { should contain_exec('UpdateSite-PhysicalPath-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name physicalPath -Value \\\"C:\\inetpub\\wwwroot\\myWebSite\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if ((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" physicalPath) -eq \\\"C:\\inetpub\\wwwroot\\myWebSite\\\") { exit 1 } else { exit 0 }\"", + })} + + it { should contain_exec('UpdateSite-ApplicationPool-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name applicationPool -Value \\\"myAppPool.example.com\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" applicationPool) -eq \\\"myAppPool.example.com\\\") { exit 1 } else { exit 0 }\"", + })} end describe 'when managing the iis site passing in all parameters' do @@ -36,6 +46,16 @@ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 1080 -IP 127.0.0.1 -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\path\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} + + it { should contain_exec('UpdateSite-PhysicalPath-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name physicalPath -Value \\\"C:\\inetpub\\wwwroot\\path\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if ((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" physicalPath) -eq \\\"C:\\inetpub\\wwwroot\\path\\\") { exit 1 } else { exit 0 }\"", + })} + + it { should contain_exec('UpdateSite-ApplicationPool-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name applicationPool -Value \\\"myAppPool.example.com\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" applicationPool) -eq \\\"myAppPool.example.com\\\") { exit 1 } else { exit 0 }\"", + })} end describe 'when managing the iis site and setting ensure to present' do @@ -51,6 +71,16 @@ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} + + it { should contain_exec('UpdateSite-PhysicalPath-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name physicalPath -Value \\\"C:\\inetpub\\wwwroot\\myWebSite\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if ((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" physicalPath) -eq \\\"C:\\inetpub\\wwwroot\\myWebSite\\\") { exit 1 } else { exit 0 }\"", + })} + + it { should contain_exec('UpdateSite-ApplicationPool-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name applicationPool -Value \\\"myAppPool.example.com\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" applicationPool) -eq \\\"myAppPool.example.com\\\") { exit 1 } else { exit 0 }\"", + })} end describe 'when managing the iis site and setting ensure to installed' do @@ -66,6 +96,16 @@ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} + + it { should contain_exec('UpdateSite-PhysicalPath-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name physicalPath -Value \\\"C:\\inetpub\\wwwroot\\myWebSite\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if ((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" physicalPath) -eq \\\"C:\\inetpub\\wwwroot\\myWebSite\\\") { exit 1 } else { exit 0 }\"", + })} + + it { should contain_exec('UpdateSite-ApplicationPool-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name applicationPool -Value \\\"myAppPool.example.com\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" applicationPool) -eq \\\"myAppPool.example.com\\\") { exit 1 } else { exit 0 }\"", + })} end describe 'when managing the iis site and setting ensure to absent' do