Skip to content

Commit 8c548fb

Browse files
committed
Migrate win_iis_webapplication module to new microsoft.iis repository
2 parents fa6cdff + f823bb6 commit 8c548fb

File tree

10 files changed

+412
-27
lines changed

10 files changed

+412
-27
lines changed

plugins/modules/web_application.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ DOCUMENTATION:
4444
- If C(pass_through), IIS will use the identity of the user or application pool identity to access the file system or network.
4545
- If C(specific_user), IIS will use the credentials provided in I(username) and I(password) to access the file system or network.
4646
type: str
47+
default: pass_through
4748
choices:
4849
- pass_through
4950
- specific_user
@@ -58,10 +59,10 @@ DOCUMENTATION:
5859
- Required when I(connect_as) is set to C(specific_user).
5960
type: str
6061
seealso:
61-
- module: microsoft.iis.win_iis_virtualdirectory
62-
- module: microsoft.iis.win_iis_webapppool
63-
- module: microsoft.iis.win_iis_webbinding
64-
- module: microsoft.iis.win_iis_website
62+
- module: community.windows.win_iis_virtualdirectory
63+
- module: community.windows.win_iis_webapppool
64+
- module: community.windows.win_iis_webbinding
65+
- module: community.windows.win_iis_website
6566
author:
6667
- Henrik Wallström (@henrikwallstrom)
6768

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!powershell
2+
3+
# Copyright: (c) 2024, Ansible Project
4+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5+
6+
7+
#AnsibleRequires -CSharpUtil Ansible.Basic
8+
9+
$spec = @{
10+
options = @{
11+
name = @{ type = "str" }
12+
site = @{ type = "str" }
13+
}
14+
supports_check_mode = $true
15+
}
16+
17+
$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec)
18+
$name = $module.Params.name
19+
$site = $module.Params.site
20+
21+
$module.Result.exists = $false
22+
$module.Result.applications = @()
23+
24+
try {
25+
# Ensure WebAdministration module is loaded
26+
if ($null -eq (Get-Module "WebAdministration" -ErrorAction SilentlyContinue)) {
27+
Import-Module WebAdministration
28+
}
29+
}
30+
catch {
31+
$module.FailJson("Failed to load WebAdministration module, Exception: $($_.Exception.Message)", $_)
32+
}
33+
34+
try {
35+
# Application Info
36+
# Get all applications
37+
if ($null -eq $name -and $null -eq $site) {
38+
$applications = Get-WebApplication
39+
}
40+
# Only name was given as input
41+
elseif ($null -ne $name -and $null -eq $site) {
42+
$applications = Get-WebApplication -Name $name
43+
}
44+
# Only site was given as input
45+
elseif ($null -eq $name -and $null -ne $site) {
46+
$applications = Get-WebApplication -Site $site
47+
}
48+
# Both name and site were given as input - handle case where name is not unique
49+
else {
50+
$applications = Get-WebApplication -Site $site -Name $name
51+
}
52+
}
53+
catch {
54+
$module.FailJson("Failed to get web applications, Exception: $($_.Exception.Message)", $_)
55+
}
56+
if ($null -ne $applications) {
57+
$module.Result.exists = $true
58+
}
59+
60+
try {
61+
foreach ($application in $applications) {
62+
$module.Result.applications += @{
63+
name = $application.path.TrimStart('/')
64+
site = $application.GetParentElement().Attributes["name"].Value
65+
application_pool = $application.ApplicationPool
66+
physical_path = $application.PhysicalPath
67+
enabled_protocols = $application.EnabledProtocols
68+
}
69+
}
70+
}
71+
catch {
72+
$module.FailJson("Failed to get application details, Exception: $($_.Exception.Message)", $_)
73+
}
74+
75+
$module.ExitJson()
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
# Copyright: (c) 2024, Ansible Project
3+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4+
5+
DOCUMENTATION:
6+
module: web_application_info
7+
short_description: Get information on IIS Web Applications
8+
description:
9+
- Returns information about IIS web applications.
10+
options:
11+
name:
12+
description:
13+
- Name of the web application.
14+
type: str
15+
site:
16+
description:
17+
- Name of the site on which the application is created.
18+
type: str
19+
seealso:
20+
- module: community.windows.win_iis_virtualdirectory
21+
- module: community.windows.win_iis_webapppool
22+
- module: community.windows.win_iis_webbinding
23+
- module: community.windows.win_iis_website
24+
author:
25+
- Ron Gershburg (@rgershbu)
26+
27+
EXAMPLES: |
28+
- name: Fetch info for all applications under siteA
29+
web_application_info:
30+
site: SiteA
31+
register: info
32+
33+
- name: Fetch info for web application MyApp
34+
web_application_info:
35+
name: MyApp
36+
register: info
37+
38+
- name: Fetch info for web application MyApp using site and name - Useful when multiple sites have same app name
39+
web_application_info:
40+
name: MyApp
41+
site: SiteA
42+
register: info
43+
44+
- name: Fetch info for all web applications that present in the system
45+
web_application_info:
46+
register: info
47+
48+
RETURN:
49+
exists:
50+
description:
51+
- Whether any applications were found.
52+
returned: success
53+
type: bool
54+
sample: true
55+
applications:
56+
description:
57+
- List of applications found.
58+
returned: success
59+
type: list
60+
elements: dict
61+
sample: '[
62+
{
63+
"application_pool": "testpool",
64+
"enabled_protocols": "http",
65+
"name": "TestAppA",
66+
"physical_path": "C:\\Users\\Administrator\\AppData\\Local\\Temp\\foldera",
67+
"site": "Test Site One"
68+
},
69+
{
70+
"application_pool": "DefaultAppPool",
71+
"enabled_protocols": "http",
72+
"name": "TestAppB",
73+
"physical_path": "C:\\Users\\Administrator\\AppData\\Local\\Temp\\folderb",
74+
"site": "Test Site Two"
75+
}
76+
]'
77+
contains:
78+
application_pool:
79+
description:
80+
- The application pool the application is associated with.
81+
type: str
82+
sample: testpool
83+
enabled_protocols:
84+
description:
85+
- The enabled protocols for the application.
86+
type: str
87+
sample: http
88+
name:
89+
description:
90+
- The name of the application.
91+
type: str
92+
sample: TestApp
93+
physical_path:
94+
description:
95+
- The physical path of the application.
96+
type: str
97+
sample: C:\Users\Administrator\AppData\Local\Temp\AppFolder
98+
site:
99+
description:
100+
- The site the application is associated with.
101+
type: str
102+
sample: Test Site One

tests/integration/targets/web_application/tasks/main.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
---
2-
- name: check if we can run the tests
3-
ansible.windows.win_shell: |
4-
$osVersion = [Version](Get-Item -LiteralPath "$env:SystemRoot\System32\kernel32.dll").VersionInfo.ProductVersion
5-
$osVersion -ge [Version]"6.2"
6-
register: run_test
7-
changed_when: False
8-
9-
- name: Run on Server 2012 and higher
10-
when: run_test.stdout | trim | bool
2+
- name: block to ensure there is a cleanup after the tests
113
block:
124
- name: ensure IIS features are installed
135
ansible.windows.win_feature:

tests/integration/targets/web_application/tasks/tests.yml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@
1919
physical_path: "{{ test_physical_path }}"
2020
register: result
2121

22+
- name: Fetch info for test app
23+
web_application_info:
24+
name: "{{ test_app_name }}"
25+
register: test_info
26+
2227
- assert:
2328
that:
24-
- 'result.changed == true'
25-
# - 'result.physical_path == test_physical_path'
29+
- result.changed == true
30+
- test_info.applications[0].physical_path == test_physical_path
2631

2732
- name: create test app (idempotent)
2833
web_application:
@@ -34,8 +39,7 @@
3439

3540
- assert:
3641
that:
37-
- 'result.changed == false'
38-
# - 'result.physical_path == test_physical_path'
42+
- result.changed == false
3943

4044
- name: set test app credentials
4145
web_application:
@@ -47,11 +51,15 @@
4751
password: "{{ test_password }}"
4852
register: result
4953

54+
- name: Fetch info for test app creds
55+
web_application_info:
56+
name: "{{ test_app_name }}"
57+
register: test_info
58+
5059
- assert:
5160
that:
52-
- 'result.changed == true'
53-
# - 'result.physical_path == test_physical_path'
54-
# - "result.connect_as == 'specific_user'"
61+
- result.changed == true
62+
- test_info.applications[0].physical_path == test_physical_path
5563

5664
- name: set test app credentials (idempotent)
5765
web_application:
@@ -65,9 +73,7 @@
6573

6674
- assert:
6775
that:
68-
- 'result.changed == false'
69-
# - 'result.physical_path == test_physical_path'
70-
# - "result.connect_as == 'specific_user'"
76+
- result.changed == false
7177

7278
- name: create new test application pool
7379
community.windows.win_iis_webapppool:
@@ -83,12 +89,16 @@
8389
application_pool: "{{ test_apppool }}"
8490
register: result
8591

92+
- name: Fetch info test_app with app pool
93+
web_application_info:
94+
name: "{{ test_app_name }}"
95+
register: test_info
96+
8697
- assert:
8798
that:
88-
- 'result.changed == true'
89-
# - 'result.physical_path == test_physical_path'
90-
# - "result.connect_as == 'pass_through'"
91-
# - "result.application_pool == test_apppool"
99+
- result.changed == true
100+
- test_info.applications[0].physical_path == test_physical_path
101+
- test_info.applications[0].application_pool == test_apppool
92102

93103
- name: Verify input failure due to missing username and password when connecting as specific user
94104
web_application:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
windows
2+
shippable/windows/group1
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
test_app_name_A: TestAppA
3+
test_app_name_B: TestAppB
4+
5+
test_site_name_A: 'Test Site One'
6+
test_site_name_B: 'Test Site Two'
7+
8+
test_user: testuser
9+
test_password: testpass
10+
11+
test_physical_path_A: "{{ remote_tmp_dir }}"
12+
test_physical_path_B: "{{ remote_tmp_dir }}/folderb"
13+
14+
test_apppool: 'testapppool'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
dependencies:
3+
- setup_remote_tmp_dir

0 commit comments

Comments
 (0)