-
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
15 changed files
with
549 additions
and
1,073 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
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,103 @@ | ||
#!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 | ||
|
||
function Get-ConnectAsInfo { | ||
param ( | ||
[string] $site, | ||
[string] $appName | ||
) | ||
|
||
# Construct the IIS path | ||
$appPath = "IIS:\Sites\$($site)\$($appName)" | ||
|
||
# Get the properties of the web application or virtual directory | ||
$appProperties = Get-ItemProperty -LiteralPath $appPath | ||
|
||
# Determine the Connect-As mode | ||
if ($appProperties.userName -and $appProperties.userName -ne "") { | ||
$connect_as = "specific_user" | ||
$username = $appProperties.userName | ||
} else { | ||
$connect_as = "pass_through" | ||
$username = "" | ||
} | ||
|
||
return @{ | ||
connect_as = $connect_as | ||
username = $username | ||
} | ||
} | ||
|
||
$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 { | ||
$getParams = @{} | ||
if ($name) { | ||
$getParams.Name = $name | ||
} | ||
if ($site) { | ||
$getParams.Site = $site | ||
} | ||
$applications = Get-WebApplication @getParams | ||
} | ||
catch { | ||
$module.FailJson("Failed to get web applications, Exception: $($_.Exception.Message)", $_) | ||
} | ||
if ($null -ne $applications) { | ||
$module.Result.exists = $true | ||
} | ||
|
||
try { | ||
$module.Result.applications = @( | ||
foreach ($application in $applications) { | ||
# Get site name from the application object | ||
$site_name = $application.GetParentElement().Attributes["name"].Value | ||
$app_name = $application.Path.TrimStart('/') | ||
|
||
# Fetch Connect-As information once | ||
$connectAsInfo = Get-ConnectAsInfo -site $site_name -appName $app_name | ||
@{ | ||
name = $app_name | ||
site = $site_name | ||
connect_as = $connectAsInfo.connect_as | ||
username = $connectAsInfo.username | ||
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,120 @@ | ||
--- | ||
# 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. | ||
requirements: | ||
- C(IISAdministration) PowerShell module | ||
options: | ||
name: | ||
description: | ||
- Name of the web application. | ||
- When not specified, information of all existing applications will be fetched or if site is specified, all applications under the site will be fetched. | ||
type: str | ||
site: | ||
description: | ||
- Name of the site on which the application is created. | ||
- When not specified, information of all existing applications will be fetched unless name is specified. | ||
- Can be used in conjunction with name to fetch information for a specific application when name is not unique. | ||
type: str | ||
seealso: | ||
- module: microsoft.iis.web_app_pool | ||
- module: microsoft.iis.website | ||
- module: microsoft.iis.web_application | ||
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" | ||
"connect_as": "pass_through" | ||
"username": "" | ||
}, | ||
{ | ||
"application_pool": "DefaultAppPool", | ||
"enabled_protocols": "http", | ||
"name": "TestAppB", | ||
"physical_path": "C:\\Users\\Administrator\\AppData\\Local\\Temp\\folderb", | ||
"site": "Test Site Two" | ||
"connect_as": "specific_user" | ||
"username": "testuser" | ||
} | ||
]' | ||
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 | ||
connect_as: | ||
description: | ||
- The type of authentication to use for this application. | ||
type: str | ||
sample: pass_through | ||
username: | ||
description: | ||
- The username of the account that can access configuration files and content for this application when I(connect_as) is set to C(specific_user). | ||
type: str | ||
sample: testuser |
Oops, something went wrong.