Skip to content

Commit

Permalink
update website physicalPath and ApplicationPool for existing websites
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Wilson committed Feb 7, 2014
1 parent d358754 commit 285c6d7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
23 changes: 21 additions & 2 deletions manifests/manage_site.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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}\\\"",
Expand All @@ -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}\\\"\"",
Expand Down
40 changes: 40 additions & 0 deletions spec/defines/manage_site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 285c6d7

Please sign in to comment.