Skip to content

Commit bd0440b

Browse files
committed
Migrate win_iis_webapplication module to new microsoft.iis repository
1 parent d89519b commit bd0440b

File tree

9 files changed

+133
-79
lines changed

9 files changed

+133
-79
lines changed

plugins/modules/web_application.ps1

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ $spec = @{
1212
state = @{ type = "str"; default = "present"; choices = "absent", "present" }
1313
physical_path = @{ type = "str"; aliases = @("path") }
1414
application_pool = @{ type = "str" }
15-
connect_as = @{ type = "str"; default = "pass_through"; choices = "specific_user", "pass_through" }
15+
connect_as = @{ type = "str"; choices = "specific_user", "pass_through" }
1616
username = @{ type = "str" }
1717
password = @{ type = "str"; no_log = $true }
1818
}
19-
required_if = @(
20-
, @("connect_as", "specific_user", @("username", "password"))
21-
)
2219
supports_check_mode = $true
2320
}
2421

@@ -33,6 +30,15 @@ $username = $module.Params.username
3330
$password = $module.Params.password
3431
$check_mode = $module.CheckMode
3532

33+
if ($connect_as -eq 'specific_user') {
34+
if (-not $username) {
35+
$module.FailJson("missing required arguments: username")
36+
}
37+
if (-not $password) {
38+
$module.FailJson("missing required arguments: password")
39+
}
40+
}
41+
3642
# Ensure WebAdministration module is loaded
3743
if ($null -eq (Get-Module "WebAdministration" -ErrorAction SilentlyContinue)) {
3844
Import-Module WebAdministration
@@ -51,20 +57,17 @@ try {
5157
# Add application
5258
if (($state -eq 'present') -and (-not $application)) {
5359
if (-not $physical_path) {
54-
$module.FailJson("missing required arguments: path")
60+
$module.FailJson("missing required arguments: physical_path")
5561
}
5662
if (-not (Test-Path -LiteralPath $physical_path)) {
57-
$module.FailJson("specified folder must already exist: path")
63+
$module.FailJson("specified folder must already exist: '$physical_path'")
5864
}
5965

6066
$application_parameters = @{
6167
Name = $name
6268
PhysicalPath = $physical_path
6369
Site = $site
64-
}
65-
66-
if ($application_pool) {
67-
$application_parameters.ApplicationPool = $application_pool
70+
ApplicationPool = $application_pool
6871
}
6972

7073
if (-not $check_mode) {
@@ -85,7 +88,7 @@ try {
8588
# Change Physical Path if needed
8689
if ($physical_path) {
8790
if (-not (Test-Path -LiteralPath $physical_path)) {
88-
$module.FailJson("specified folder must already exist: path")
91+
$module.FailJson("specified folder must already exist: '$physical_path'")
8992
}
9093

9194
$folder = Get-Item -LiteralPath $physical_path

plugins/modules/web_application.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ DOCUMENTATION:
77
short_description: Configures IIS web applications
88
description: >
99
Creates, removes, and configures IIS web applications.
10+
requirements:
11+
- C(IISAdministration) PowerShell module
1012
options:
1113
name:
1214
description:
@@ -21,6 +23,8 @@ DOCUMENTATION:
2123
state:
2224
description:
2325
- State of the web application.
26+
- If C(absent), the web application will be removed.
27+
- If C(present), the web application will be created if not already present.
2428
type: str
2529
choices:
2630
- absent
@@ -44,7 +48,6 @@ DOCUMENTATION:
4448
- If C(pass_through), IIS will use the identity of the user or application pool identity to access the file system or network.
4549
- If C(specific_user), IIS will use the credentials provided in I(username) and I(password) to access the file system or network.
4650
type: str
47-
default: pass_through
4851
choices:
4952
- pass_through
5053
- specific_user
@@ -59,19 +62,32 @@ DOCUMENTATION:
5962
- Required when I(connect_as) is set to C(specific_user).
6063
type: str
6164
seealso:
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
65+
- module: microsoft.iis.web_app_pool
66+
- module: microsoft.iis.website
67+
- module: microsoft.iis.web_application_info
6668
author:
6769
- Henrik Wallström (@henrikwallstrom)
6870

6971
EXAMPLES: |
70-
- name: Add ACME webapplication on IIS.
72+
- name: Add ACME web application on IIS.
7173
microsoft.iis.web_application:
7274
name: api
7375
site: acme
7476
state: present
7577
physical_path: C:\apps\acme\api
78+
79+
- name: Change connect_as to be specific user.
80+
microsoft.iis.web_application:
81+
name: api
82+
site: acme
83+
connect_as: specific_user
84+
username: acmeuser
85+
password: acmepassword
86+
87+
- name: Delete ACME web application on IIS.
88+
microsoft.iis.web_application:
89+
state: absent
90+
name: api
91+
site: acme
7692
7793
RETURN: {}

plugins/modules/web_application_info.ps1

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,14 @@ catch {
3232
}
3333

3434
try {
35-
# Application Info
36-
# Get all applications
37-
if ($null -eq $name -and $null -eq $site) {
38-
$applications = Get-WebApplication
35+
$getParams = @{}
36+
if ($name) {
37+
$getParams.Name = $name
3938
}
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
39+
if ($site) {
40+
$getParams.Site = $site
5141
}
42+
$applications = Get-WebApplication @getParams
5243
}
5344
catch {
5445
$module.FailJson("Failed to get web applications, Exception: $($_.Exception.Message)", $_)
@@ -58,15 +49,17 @@ if ($null -ne $applications) {
5849
}
5950

6051
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
52+
$module.Result.applications = @(
53+
foreach ($application in $applications) {
54+
@{
55+
name = $application.path.TrimStart('/')
56+
site = $application.GetParentElement().Attributes["name"].Value
57+
application_pool = $application.ApplicationPool
58+
physical_path = $application.PhysicalPath
59+
enabled_protocols = $application.EnabledProtocols
60+
}
6861
}
69-
}
62+
)
7063
}
7164
catch {
7265
$module.FailJson("Failed to get application details, Exception: $($_.Exception.Message)", $_)

plugins/modules/web_application_info.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ DOCUMENTATION:
77
short_description: Get information on IIS Web Applications
88
description:
99
- Returns information about IIS web applications.
10+
requirements:
11+
- C(IISAdministration) PowerShell module
1012
options:
1113
name:
1214
description:
1315
- Name of the web application.
16+
- When not specified, information of all existing applications will be fetched or if site is specified, all applications under the site will be fetched.
1417
type: str
1518
site:
1619
description:
1720
- Name of the site on which the application is created.
21+
- When not specified, information of all existing applications will be fetched unless name is specified.
22+
- Can be used in conjunction with name to fetch information for a specific application when name is not unique.
1823
type: str
1924
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
25+
- module: microsoft.iis.web_app_pool
26+
- module: microsoft.iis.website
27+
- module: microsoft.iis.web_application
2428
author:
2529
- Ron Gershburg (@rgershbu)
2630

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
windows
2-
shippable/windows/group4
3-
# unstable - Random IIS configuration errors
2+
shippable/windows/group1

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
name: "{{ test_app_name }}"
4444

4545
- name: remove test application pool
46-
community.windows.win_iis_webapppool:
46+
web_app_pool:
4747
name: "{{ test_apppool }}"
4848
state: absent
4949

5050
- name: remove test site
51-
win_iis_website:
51+
website:
5252
name: "{{ test_site_name }}"
5353
state: absent
5454

@@ -62,15 +62,3 @@
6262
- assert:
6363
that:
6464
- "stat_result.stat.checksum == copy_result.checksum"
65-
66-
- name: remove IIS feature if it was installed
67-
ansible.windows.win_feature:
68-
name: Web-Server
69-
state: absent
70-
include_management_tools: True
71-
when: feature_install is changed
72-
register: feature_uninstall
73-
74-
- name: reboot after removing IIS features
75-
ansible.windows.win_reboot:
76-
when: feature_uninstall.reboot_required | default(False)

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

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: test site exists, but stopped in case of duplicate web binding
3-
community.windows.win_iis_website:
3+
website:
44
name: "{{ test_site_name }}"
55
state: stopped
66
physical_path: 'C:\inetpub\wwwroot'
@@ -11,6 +11,25 @@
1111
site: "{{ test_site_name }}"
1212
name: "{{ test_app_name }}"
1313

14+
- name: create test app - check mode
15+
web_application:
16+
state: present
17+
site: "{{ test_site_name }}"
18+
name: "{{ test_app_name }}"
19+
physical_path: "{{ test_physical_path }}"
20+
check_mode: true
21+
register: result
22+
23+
- name: Fetch info for test app - check mode
24+
web_application_info:
25+
name: "{{ test_app_name }}"
26+
register: test_info_check
27+
28+
- assert:
29+
that:
30+
- result.changed == true
31+
- not test_info_check.exists
32+
1433
- name: create test app
1534
web_application:
1635
state: present
@@ -76,7 +95,7 @@
7695
- result.changed == false
7796

7897
- name: create new test application pool
79-
community.windows.win_iis_webapppool:
98+
web_app_pool:
8099
name: "{{ test_apppool }}"
81100
state: present
82101

@@ -108,4 +127,48 @@
108127
connect_as: specific_user
109128
application_pool: "{{ test_apppool }}"
110129
register: failure
111-
failed_when: "'connect_as is specific_user but all of the following are missing: username, password' not in failure.msg"
130+
failed_when: "'missing required arguments: username' not in failure.msg"
131+
132+
- name: Remove test app - check mode
133+
web_application:
134+
state: absent
135+
site: "{{ test_site_name }}"
136+
name: "{{ test_app_name }}"
137+
check_mode: true
138+
139+
- name: Fetch info for test app after removal - check mode
140+
web_application_info:
141+
name: "{{ test_app_name }}"
142+
register: test_info_check_removal
143+
144+
- assert:
145+
that:
146+
- result.changed == true
147+
- test_info_check_removal.exists
148+
149+
- name: Remove test app
150+
web_application:
151+
state: absent
152+
site: "{{ test_site_name }}"
153+
name: "{{ test_app_name }}"
154+
155+
- name: Fetch info for test app after removal
156+
web_application_info:
157+
name: "{{ test_app_name }}"
158+
register: test_info_check_removal
159+
160+
- assert:
161+
that:
162+
- result.changed == true
163+
- not test_info_check_removal.exists
164+
165+
- name: Remove test app (idempotent)
166+
web_application:
167+
state: absent
168+
site: "{{ test_site_name }}"
169+
name: "{{ test_app_name }}"
170+
register: result
171+
172+
- assert:
173+
that:
174+
- result.changed == false

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@
5454
name: "{{ test_app_name_B }}"
5555

5656
- name: remove test application pool
57-
community.windows.win_iis_webapppool:
57+
web_app_pool:
5858
name: "{{ test_apppool }}"
5959
state: absent
6060

6161
- name: remove test site A
62-
win_iis_website:
62+
website:
6363
name: "{{ test_site_name_A }}"
6464
state: absent
6565

6666
- name: remove test site B
67-
win_iis_website:
67+
website:
6868
name: "{{ test_site_name_B }}"
6969
state: absent
7070

@@ -87,15 +87,3 @@
8787
- assert:
8888
that:
8989
- "stat_result.stat.checksum == copy_result.checksum"
90-
91-
- name: remove IIS feature if it was installed
92-
ansible.windows.win_feature:
93-
name: Web-Server
94-
state: absent
95-
include_management_tools: True
96-
when: feature_install is changed
97-
register: feature_uninstall
98-
99-
- name: reboot after removing IIS features
100-
ansible.windows.win_reboot:
101-
when: feature_uninstall.reboot_required | default(False)

tests/integration/targets/web_application_info/tasks/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
test_sites:
55
- "{{ test_site_name_A }}"
66
- "{{ test_site_name_B }}"
7-
community.windows.win_iis_website:
7+
website:
88
name: "{{ item }}"
99
state: stopped
1010
physical_path: 'C:\inetpub\wwwroot'

0 commit comments

Comments
 (0)