|
|
@ -5,38 +5,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
#Requires -Module Ansible.ModuleUtils.Legacy
|
|
|
|
#Requires -Module Ansible.ModuleUtils.Legacy
|
|
|
|
|
|
|
|
|
|
|
|
$params = Parse-Args $args;
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
|
|
|
|
|
|
# Name parameter
|
|
|
|
$params = Parse-Args $args
|
|
|
|
$name = Get-Attr $params "name" $FALSE;
|
|
|
|
$name = Get-AnsibleParam -obj $params -name "name" -type "str" -failifempty $true
|
|
|
|
If ($name -eq $FALSE) {
|
|
|
|
$application_pool = Get-AnsibleParam -obj $params -name "application_pool" -type "str"
|
|
|
|
Fail-Json @{} "missing required argument: name";
|
|
|
|
$physical_path = Get-AnsibleParam -obj $params -name "physical_path" -type "str"
|
|
|
|
}
|
|
|
|
$site_id = Get-AnsibleParam -obj $params -name "site_id" -type "str"
|
|
|
|
|
|
|
|
$state = Get-AnsibleParam -obj $params -name "state" -type "str" -validateset "absent","restarted","started","stopped"
|
|
|
|
# State parameter
|
|
|
|
|
|
|
|
$state = Get-Attr $params "state" $FALSE;
|
|
|
|
|
|
|
|
$state.ToString().ToLower();
|
|
|
|
|
|
|
|
If (($state -ne $FALSE) -and ($state -ne 'started') -and ($state -ne 'stopped') -and ($state -ne 'restarted') -and ($state -ne 'absent')) {
|
|
|
|
|
|
|
|
Fail-Json @{} "state is '$state'; must be 'started', 'restarted', 'stopped' or 'absent'"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Path parameter
|
|
|
|
|
|
|
|
$physical_path = Get-Attr $params "physical_path" $FALSE;
|
|
|
|
|
|
|
|
$site_id = Get-Attr $params "site_id" $FALSE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Application Pool Parameter
|
|
|
|
|
|
|
|
$application_pool = Get-Attr $params "application_pool" $FALSE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Binding Parameters
|
|
|
|
# Binding Parameters
|
|
|
|
$bind_port = Get-Attr $params "port" $FALSE;
|
|
|
|
$bind_port = Get-AnsibleParam -obj $params -name "port" -type "int"
|
|
|
|
$bind_ip = Get-Attr $params "ip" $FALSE;
|
|
|
|
$bind_ip = Get-AnsibleParam -obj $params -name "ip" -type "str"
|
|
|
|
$bind_hostname = Get-Attr $params "hostname" $FALSE;
|
|
|
|
$bind_hostname = Get-AnsibleParam -obj $params -name "hostname" -type "str"
|
|
|
|
$bind_ssl = Get-Attr $params "ssl" $FALSE;
|
|
|
|
$bind_ssl = Get-AnsibleParam -obj $params -name "ssl" -type "str"
|
|
|
|
|
|
|
|
|
|
|
|
# Custom site Parameters from string where properties
|
|
|
|
# Custom site Parameters from string where properties
|
|
|
|
# are separated by a pipe and property name/values by colon.
|
|
|
|
# are separated by a pipe and property name/values by colon.
|
|
|
|
# Ex. "foo:1|bar:2"
|
|
|
|
# Ex. "foo:1|bar:2"
|
|
|
|
$parameters = Get-Attr $params "parameters" $null;
|
|
|
|
$parameters = Get-AnsibleParam -obj $params -name "parameters" -type "str"
|
|
|
|
if($parameters -ne $null) {
|
|
|
|
if($parameters -ne $null) {
|
|
|
|
$parameters = @($parameters -split '\|' | ForEach {
|
|
|
|
$parameters = @($parameters -split '\|' | ForEach {
|
|
|
|
return ,($_ -split "\:", 2);
|
|
|
|
return ,($_ -split "\:", 2);
|
|
|
@ -53,7 +40,7 @@ if ((Get-Module "WebAdministration" -ErrorAction SilentlyContinue) -eq $null) {
|
|
|
|
$result = @{
|
|
|
|
$result = @{
|
|
|
|
site = @{}
|
|
|
|
site = @{}
|
|
|
|
changed = $false
|
|
|
|
changed = $false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Site info
|
|
|
|
# Site info
|
|
|
|
$site = Get-Website | Where { $_.Name -eq $name }
|
|
|
|
$site = Get-Website | Where { $_.Name -eq $name }
|
|
|
@ -61,17 +48,17 @@ $site = Get-Website | Where { $_.Name -eq $name }
|
|
|
|
Try {
|
|
|
|
Try {
|
|
|
|
# Add site
|
|
|
|
# Add site
|
|
|
|
If(($state -ne 'absent') -and (-not $site)) {
|
|
|
|
If(($state -ne 'absent') -and (-not $site)) {
|
|
|
|
If ($physical_path -eq $FALSE) {
|
|
|
|
If (-not $physical_path) {
|
|
|
|
Fail-Json @{} "missing required arguments: physical_path"
|
|
|
|
Fail-Json -obj $result -message "missing required arguments: physical_path"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ElseIf (-not (Test-Path $physical_path)) {
|
|
|
|
ElseIf (-not (Test-Path $physical_path)) {
|
|
|
|
Fail-Json @{} "specified folder must already exist: physical_path"
|
|
|
|
Fail-Json -obj $result -message "specified folder must already exist: physical_path"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$site_parameters = @{
|
|
|
|
$site_parameters = @{
|
|
|
|
Name = $name
|
|
|
|
Name = $name
|
|
|
|
PhysicalPath = $physical_path
|
|
|
|
PhysicalPath = $physical_path
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($application_pool) {
|
|
|
|
If ($application_pool) {
|
|
|
|
$site_parameters.ApplicationPool = $application_pool
|
|
|
|
$site_parameters.ApplicationPool = $application_pool
|
|
|
@ -114,7 +101,7 @@ Try {
|
|
|
|
# Change Physical Path if needed
|
|
|
|
# Change Physical Path if needed
|
|
|
|
if($physical_path) {
|
|
|
|
if($physical_path) {
|
|
|
|
If (-not (Test-Path $physical_path)) {
|
|
|
|
If (-not (Test-Path $physical_path)) {
|
|
|
|
Fail-Json @{} "specified folder must already exist: physical_path"
|
|
|
|
Fail-Json -obj $result -message "specified folder must already exist: physical_path"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$folder = Get-Item $physical_path
|
|
|
|
$folder = Get-Item $physical_path
|
|
|
@ -165,7 +152,7 @@ Try {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Catch
|
|
|
|
Catch
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Fail-Json @{} $_.Exception.Message
|
|
|
|
Fail-Json -obj $result -message $_.Exception.Message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($state -ne 'absent')
|
|
|
|
if ($state -ne 'absent')
|
|
|
@ -185,4 +172,4 @@ if ($site)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Exit-Json $result
|
|
|
|
Exit-Json -obj $result
|
|
|
|