-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate win_iis_webapplication module to new microsoft.iis repository
- Loading branch information
Showing
10 changed files
with
412 additions
and
27 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!powershell | ||
|
||
# Copyright: (c) 2024, Ansible Project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
|
||
#AnsibleRequires -CSharpUtil Ansible.Basic | ||
|
||
$spec = @{ | ||
options = @{ | ||
name = @{ type = "str" } | ||
site = @{ type = "str" } | ||
} | ||
supports_check_mode = $true | ||
} | ||
|
||
$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec) | ||
$name = $module.Params.name | ||
$site = $module.Params.site | ||
|
||
$module.Result.exists = $false | ||
$module.Result.applications = @() | ||
|
||
try { | ||
# Ensure WebAdministration module is loaded | ||
if ($null -eq (Get-Module "WebAdministration" -ErrorAction SilentlyContinue)) { | ||
Import-Module WebAdministration | ||
} | ||
} | ||
catch { | ||
$module.FailJson("Failed to load WebAdministration module, Exception: $($_.Exception.Message)", $_) | ||
} | ||
|
||
try { | ||
# Application Info | ||
# Get all applications | ||
if ($null -eq $name -and $null -eq $site) { | ||
$applications = Get-WebApplication | ||
} | ||
# Only name was given as input | ||
elseif ($null -ne $name -and $null -eq $site) { | ||
$applications = Get-WebApplication -Name $name | ||
} | ||
# Only site was given as input | ||
elseif ($null -eq $name -and $null -ne $site) { | ||
$applications = Get-WebApplication -Site $site | ||
} | ||
# Both name and site were given as input - handle case where name is not unique | ||
else { | ||
$applications = Get-WebApplication -Site $site -Name $name | ||
} | ||
} | ||
catch { | ||
$module.FailJson("Failed to get web applications, Exception: $($_.Exception.Message)", $_) | ||
} | ||
if ($null -ne $applications) { | ||
$module.Result.exists = $true | ||
} | ||
|
||
try { | ||
foreach ($application in $applications) { | ||
$module.Result.applications += @{ | ||
name = $application.path.TrimStart('/') | ||
site = $application.GetParentElement().Attributes["name"].Value | ||
application_pool = $application.ApplicationPool | ||
physical_path = $application.PhysicalPath | ||
enabled_protocols = $application.EnabledProtocols | ||
} | ||
} | ||
} | ||
catch { | ||
$module.FailJson("Failed to get application details, Exception: $($_.Exception.Message)", $_) | ||
} | ||
|
||
$module.ExitJson() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
--- | ||
# Copyright: (c) 2024, Ansible Project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
DOCUMENTATION: | ||
module: web_application_info | ||
short_description: Get information on IIS Web Applications | ||
description: | ||
- Returns information about IIS web applications. | ||
options: | ||
name: | ||
description: | ||
- Name of the web application. | ||
type: str | ||
site: | ||
description: | ||
- Name of the site on which the application is created. | ||
type: str | ||
seealso: | ||
- module: community.windows.win_iis_virtualdirectory | ||
- module: community.windows.win_iis_webapppool | ||
- module: community.windows.win_iis_webbinding | ||
- module: community.windows.win_iis_website | ||
author: | ||
- Ron Gershburg (@rgershbu) | ||
|
||
EXAMPLES: | | ||
- name: Fetch info for all applications under siteA | ||
web_application_info: | ||
site: SiteA | ||
register: info | ||
- name: Fetch info for web application MyApp | ||
web_application_info: | ||
name: MyApp | ||
register: info | ||
- name: Fetch info for web application MyApp using site and name - Useful when multiple sites have same app name | ||
web_application_info: | ||
name: MyApp | ||
site: SiteA | ||
register: info | ||
- name: Fetch info for all web applications that present in the system | ||
web_application_info: | ||
register: info | ||
RETURN: | ||
exists: | ||
description: | ||
- Whether any applications were found. | ||
returned: success | ||
type: bool | ||
sample: true | ||
applications: | ||
description: | ||
- List of applications found. | ||
returned: success | ||
type: list | ||
elements: dict | ||
sample: '[ | ||
{ | ||
"application_pool": "testpool", | ||
"enabled_protocols": "http", | ||
"name": "TestAppA", | ||
"physical_path": "C:\\Users\\Administrator\\AppData\\Local\\Temp\\foldera", | ||
"site": "Test Site One" | ||
}, | ||
{ | ||
"application_pool": "DefaultAppPool", | ||
"enabled_protocols": "http", | ||
"name": "TestAppB", | ||
"physical_path": "C:\\Users\\Administrator\\AppData\\Local\\Temp\\folderb", | ||
"site": "Test Site Two" | ||
} | ||
]' | ||
contains: | ||
application_pool: | ||
description: | ||
- The application pool the application is associated with. | ||
type: str | ||
sample: testpool | ||
enabled_protocols: | ||
description: | ||
- The enabled protocols for the application. | ||
type: str | ||
sample: http | ||
name: | ||
description: | ||
- The name of the application. | ||
type: str | ||
sample: TestApp | ||
physical_path: | ||
description: | ||
- The physical path of the application. | ||
type: str | ||
sample: C:\Users\Administrator\AppData\Local\Temp\AppFolder | ||
site: | ||
description: | ||
- The site the application is associated with. | ||
type: str | ||
sample: Test Site One |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
windows | ||
shippable/windows/group1 |
14 changes: 14 additions & 0 deletions
14
tests/integration/targets/web_application_info/defaults/main.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
test_app_name_A: TestAppA | ||
test_app_name_B: TestAppB | ||
|
||
test_site_name_A: 'Test Site One' | ||
test_site_name_B: 'Test Site Two' | ||
|
||
test_user: testuser | ||
test_password: testpass | ||
|
||
test_physical_path_A: "{{ remote_tmp_dir }}" | ||
test_physical_path_B: "{{ remote_tmp_dir }}/folderb" | ||
|
||
test_apppool: 'testapppool' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
dependencies: | ||
- setup_remote_tmp_dir |
Oops, something went wrong.