win_iis_webapppool module, fixes and improvement (#20680)
* fixes and improvments for win_iis_webapppool module * fixes following review feedback on win_iis_webapppool * Fixed a too-long line in win_iis_webapppool documentation. * Fixed trailing whitespace for pep8 compliance in documentation win_iis_webapppool.py * fixed bracket bug * module parameter attributes now populated. Switched to hashtable for result object. Removed remaining ; statement terminators. * Remove example that was causing CI check failure
This commit is contained in:
parent
4f3dade266
commit
99c594e573
2 changed files with 118 additions and 46 deletions
|
@ -20,42 +20,40 @@
|
||||||
|
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
# POWERSHELL_COMMON
|
# POWERSHELL_COMMON
|
||||||
|
$params = Parse-Args $args
|
||||||
$params = Parse-Args $args;
|
|
||||||
|
|
||||||
# Name parameter
|
# Name parameter
|
||||||
$name = Get-Attr $params "name" $FALSE;
|
$name = Get-AnsibleParam -obj $params -name "name" -type "string" -failifempty $true
|
||||||
If ($name -eq $FALSE) {
|
|
||||||
Fail-Json (New-Object psobject) "missing required argument: name";
|
|
||||||
}
|
|
||||||
|
|
||||||
# State parameter
|
# State parameter
|
||||||
$state = Get-Attr $params "state" $FALSE;
|
$state = Get-AnsibleParam -obj $params -name "state" -default "present" -validateSet "started","restarted","stopped","absent"
|
||||||
$valid_states = ('started', 'restarted', 'stopped', 'absent');
|
|
||||||
If (($state -Ne $FALSE) -And ($state -NotIn $valid_states)) {
|
|
||||||
Fail-Json $result "state is '$state'; must be $($valid_states)"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Attributes parameter - Pipe separated list of attributes where
|
# Attributes parameter - Pipe separated list of attributes where
|
||||||
# keys and values are separated by comma (paramA:valyeA|paramB:valueB)
|
# keys and values are separated by comma (paramA:valyeA|paramB:valueB)
|
||||||
$attributes = @{};
|
$attributes = @{};
|
||||||
If (Get-Member -InputObject $params -Name attributes) {
|
If (Get-Member -InputObject $params -Name attributes) {
|
||||||
$params.attributes -split '\|' | foreach {
|
$params.attributes -split '\|' | foreach {
|
||||||
$key, $value = $_ -split "\:";
|
$key, $value = $_ -split "\:"
|
||||||
$attributes.Add($key, $value);
|
$attributes.Add($key, $value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ensure WebAdministration module is loaded
|
# Ensure WebAdministration module is loaded
|
||||||
if ((Get-Module "WebAdministration" -ErrorAction SilentlyContinue) -eq $NULL){
|
if ((Get-Module "WebAdministration" -ErrorAction SilentlyContinue) -eq $NULL){
|
||||||
Import-Module WebAdministration
|
Import-Module WebAdministration
|
||||||
|
$web_admin_dll_path = Join-Path $env:SystemRoot system32\inetsrv\Microsoft.Web.Administration.dll
|
||||||
|
Add-Type -Path $web_admin_dll_path
|
||||||
|
$t = [Type]"Microsoft.Web.Administration.ApplicationPool"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Result
|
# Result
|
||||||
$result = New-Object psobject @{
|
$result = @{
|
||||||
changed = $FALSE
|
changed = $FALSE
|
||||||
attributes = $attributes
|
# attributes = $attributes
|
||||||
};
|
}
|
||||||
|
|
||||||
|
$result.attributes = $attributes
|
||||||
|
|
||||||
# Get pool
|
# Get pool
|
||||||
$pool = Get-Item IIS:\AppPools\$name
|
$pool = Get-Item IIS:\AppPools\$name
|
||||||
|
@ -77,9 +75,15 @@ try {
|
||||||
if($pool) {
|
if($pool) {
|
||||||
# Set properties
|
# Set properties
|
||||||
$attributes.GetEnumerator() | foreach {
|
$attributes.GetEnumerator() | foreach {
|
||||||
$newParameter = $_;
|
$newParameter = $_
|
||||||
$currentParameter = Get-ItemProperty ("IIS:\AppPools\" + $name) $newParameter.Key
|
$currentParameter = Get-ItemProperty ("IIS:\AppPools\" + $name) $newParameter.Key
|
||||||
if(-not $currentParameter -or ($currentParameter.Value -as [String]) -ne $newParameter.Value) {
|
$currentParamVal = ""
|
||||||
|
try {
|
||||||
|
$currentParamVal = $currentParameter
|
||||||
|
} catch {
|
||||||
|
$currentParamVal = $currentParameter.Value
|
||||||
|
}
|
||||||
|
if(-not $currentParamVal -or ($currentParamVal -as [String]) -ne $newParameter.Value) {
|
||||||
Set-ItemProperty ("IIS:\AppPools\" + $name) $newParameter.Key $newParameter.Value
|
Set-ItemProperty ("IIS:\AppPools\" + $name) $newParameter.Key $newParameter.Value
|
||||||
$result.changed = $TRUE
|
$result.changed = $TRUE
|
||||||
}
|
}
|
||||||
|
@ -90,7 +94,7 @@ try {
|
||||||
Stop-WebAppPool -Name $name -ErrorAction Stop
|
Stop-WebAppPool -Name $name -ErrorAction Stop
|
||||||
$result.changed = $TRUE
|
$result.changed = $TRUE
|
||||||
}
|
}
|
||||||
if ((($state -eq 'started') -and ($pool.State -eq 'Stopped'))) {
|
if (($state -eq 'started') -and ($pool.State -eq 'Stopped')) {
|
||||||
Start-WebAppPool -Name $name -ErrorAction Stop
|
Start-WebAppPool -Name $name -ErrorAction Stop
|
||||||
$result.changed = $TRUE
|
$result.changed = $TRUE
|
||||||
}
|
}
|
||||||
|
@ -114,10 +118,22 @@ if ($pool)
|
||||||
$result.info = @{
|
$result.info = @{
|
||||||
name = $pool.Name
|
name = $pool.Name
|
||||||
state = $pool.State
|
state = $pool.State
|
||||||
attributes = New-Object psobject @{}
|
attributes = @{}
|
||||||
};
|
};
|
||||||
|
|
||||||
$pool.Attributes | ForEach { $result.info.attributes.Add($_.Name, $_.Value)};
|
$pool.Attributes | ForEach {
|
||||||
|
# lookup name if enum
|
||||||
|
if ($_.Schema.Type -eq 'enum') {
|
||||||
|
$propertyName = $_.Name.Substring(0,1).ToUpper() + $_.Name.Substring(1)
|
||||||
|
$enum = [Microsoft.Web.Administration.ApplicationPool].GetProperty($propertyName).PropertyType.FullName
|
||||||
|
$enum_names = [Enum]::GetNames($enum)
|
||||||
|
$result.info.attributes.Add($_.Name, $enum_names[$_.Value])
|
||||||
|
} else {
|
||||||
|
$result.info.attributes.Add($_.Name, $_.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Exit-Json $result
|
Exit-Json $result
|
||||||
|
|
||||||
|
|
|
@ -18,22 +18,22 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'status': ['preview'],
|
ANSIBLE_METADATA = {'status': ['preview'],
|
||||||
'supported_by': 'community',
|
'supported_by': 'community',
|
||||||
'version': '1.0'}
|
'version': '1.0'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r'''
|
||||||
---
|
---
|
||||||
module: win_iis_webapppool
|
module: win_iis_webapppool
|
||||||
version_added: "2.0"
|
version_added: "2.0"
|
||||||
short_description: Configures a IIS Web Application Pool.
|
short_description: Configures an IIS Web Application Pool.
|
||||||
description:
|
description:
|
||||||
- Creates, Removes and configures a IIS Web Application Pool
|
- Creates, Removes and configures an IIS Web Application Pool
|
||||||
options:
|
options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Names of application pool
|
- Name of application pool
|
||||||
required: true
|
required: true
|
||||||
default: null
|
default: null
|
||||||
aliases: []
|
aliases: []
|
||||||
|
@ -47,51 +47,107 @@ options:
|
||||||
- restarted
|
- restarted
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
aliases: []
|
|
||||||
attributes:
|
attributes:
|
||||||
description:
|
description:
|
||||||
- Application Pool attributes from string where attributes are separated by a pipe and attribute name/values by colon Ex. "foo:1|bar:2"
|
- Application Pool attributes from string where attributes are separated by a pipe and attribute name/values by colon Ex. "foo:1|bar:2".
|
||||||
|
- The following attributes may only have the following names.
|
||||||
|
- managedPipelineMode may be either "Integrated" or "Classic".
|
||||||
|
- startMode may be either "OnDemand" or "AlwaysRunning".
|
||||||
|
- state may be one of "Starting", "Started", "Stopping", "Stopped", "Unknown".
|
||||||
|
Use the C(state) module parameter to modify, states shown are reflect the possible runtime values.
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
aliases: []
|
|
||||||
author: Henrik Wallström
|
author: Henrik Wallström
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
- name: Return information about an existing application pool
|
- name: return information about an existing application pool
|
||||||
win_iis_webapppool:
|
win_iis_webapppool:
|
||||||
name: DefaultAppPool
|
name: DefaultAppPool
|
||||||
|
|
||||||
- name: Ensure AppPool is started
|
- name: Create a new application pool in 'Started' state
|
||||||
win_iis_webapppool:
|
win_iis_webapppool:
|
||||||
name: AppPool
|
name: AppPool
|
||||||
state: started
|
state: started
|
||||||
|
|
||||||
- name: Ensure AppPool is stopped
|
- name: Stop an application pool
|
||||||
win_iis_webapppool:
|
win_iis_webapppool:
|
||||||
name: AppPool
|
name: AppPool
|
||||||
state: stopped
|
state: stopped
|
||||||
|
|
||||||
- name: Restart AppPool
|
- name: Restart an application pool
|
||||||
win_iis_webapppool:
|
win_iis_webapppool:
|
||||||
name: AppPool
|
name: AppPool
|
||||||
state: restart
|
state: restart
|
||||||
|
|
||||||
- name: Change application pool attributes without touching state
|
- name: Changes application pool attributes without touching state
|
||||||
win_iis_webapppool:
|
win_iis_webapppool:
|
||||||
name: AppPool
|
name: AppPool
|
||||||
attributes: managedRuntimeVersion:v4.0|autoStart:false
|
attributes: 'managedRuntimeVersion:v4.0|autoStart:false'
|
||||||
|
|
||||||
- name: Create AnotherAppPool and start it using .NET 4.0 and disabling autostart
|
- name: Creates an application pool and sets attributes
|
||||||
win_iis_webapppool:
|
win_iis_webapppool:
|
||||||
name: AnotherAppPool
|
name: AnotherAppPool
|
||||||
state: started
|
state: started
|
||||||
attributes: managedRuntimeVersion:v4.0|autoStart:false
|
attributes: 'managedRuntimeVersion:v4.0|autoStart:false'
|
||||||
|
|
||||||
- name: Create AppPool and start it using .NET 4.0
|
# Playbook example
|
||||||
|
---
|
||||||
|
|
||||||
|
- name: App Pool with .NET 4.0
|
||||||
win_iis_webapppool:
|
win_iis_webapppool:
|
||||||
name: AppPool
|
name: 'AppPool'
|
||||||
state: started
|
state: started
|
||||||
attributes: managedRuntimeVersion:v4.0
|
attributes: managedRuntimeVersion:v4.0
|
||||||
register: webapppool
|
register: webapppool
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
attributes:
|
||||||
|
description:
|
||||||
|
- Application Pool attributes from that were processed by this module invocation.
|
||||||
|
returned: success
|
||||||
|
type: dictionary
|
||||||
|
sample:
|
||||||
|
"enable32BitAppOnWin64": "true"
|
||||||
|
"managedRuntimeVersion": "v4.0"
|
||||||
|
"managedPipelineMode": "Classic"
|
||||||
|
info:
|
||||||
|
description: Information on current state of the Application Pool
|
||||||
|
returned: success
|
||||||
|
type: dictionary
|
||||||
|
sample:
|
||||||
|
contains:
|
||||||
|
attributes:
|
||||||
|
description: key value pairs showing the current Application Pool attributes
|
||||||
|
returned: success
|
||||||
|
type: dictionary
|
||||||
|
sample:
|
||||||
|
"autoStart": true
|
||||||
|
"managedRuntimeLoader": "webengine4.dll"
|
||||||
|
"managedPipelineMode": "Classic"
|
||||||
|
"name": "DefaultAppPool"
|
||||||
|
"CLRConfigFile": ""
|
||||||
|
"passAnonymousToken": true
|
||||||
|
"applicationPoolSid": "S-1-5-82-1352790163-598702362-1775843902-1923651883-1762956711"
|
||||||
|
"queueLength": 1000
|
||||||
|
"managedRuntimeVersion": "v4.0"
|
||||||
|
"state": "Started"
|
||||||
|
"enableConfigurationOverride": true
|
||||||
|
"startMode": "OnDemand"
|
||||||
|
"enable32BitAppOnWin64": true
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Name of Application Pool that was processed by this module invocation.
|
||||||
|
returned: success
|
||||||
|
type: string
|
||||||
|
sample: "DefaultAppPool"
|
||||||
|
state:
|
||||||
|
description:
|
||||||
|
- Current runtime state of the pool as the module completed.
|
||||||
|
returned: success
|
||||||
|
type: string
|
||||||
|
sample: "Started"
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue