-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from p3ck/manage_iis
Add validated role windows_manage_iis
- Loading branch information
Showing
10 changed files
with
216 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
# defaults file for | ||
windows_manage_iis_operation: create |
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,7 @@ | ||
--- | ||
# handlers file for windows_managed_iis | ||
- name: Restart iis service | ||
ansible.windows.win_service: | ||
name: W3Svc | ||
state: restarted | ||
start_mode: auto |
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,36 @@ | ||
--- | ||
argument_specs: | ||
main: | ||
version_added: 1.0.0 | ||
short_description: A role to Create/Delete an IIS Web server. | ||
description: | ||
- A role to Create/Delete an IIS Web server. | ||
options: | ||
windows_manage_iis_operation: | ||
type: str | ||
description: Operation to perform. | ||
default: "create" | ||
choices: ["create", "delete"] | ||
windows_manage_iis_delete_option: | ||
type: str | ||
description: | ||
- used with O(windows_manage_iis_operation=delete). | ||
- This option specifies whether to delete all resources including the IIS service, or only the server. | ||
default: "server" | ||
choices: ["all", "server"] | ||
windows_manage_iis_name: | ||
type: str | ||
description: The name of the Server. | ||
required: true | ||
windows_manage_iis_port: | ||
type: int | ||
description: The network port that the Server will listen on. | ||
default: 80 | ||
required: true | ||
windows_manage_iis_path: | ||
type: str | ||
description: The path on disk where the web content will be served from. | ||
required: true | ||
windows_manage_iis_test_message: | ||
type: str | ||
description: The test message that will be used in the index.html. |
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,69 @@ | ||
--- | ||
# tasks file for windows_manage_iis/create | ||
|
||
- name: Install IIS | ||
ansible.windows.win_feature: | ||
name: Web-Server | ||
state: present | ||
register: windows_manage_iis_output | ||
|
||
- name: Update Results w/win_feature | ||
ansible.builtin.set_fact: | ||
windows_manage_iis_results: "{{ windows_manage_iis_results | default({}) | combine({'win_feature': windows_manage_iis_output}) }}" | ||
|
||
- name: Create site directory structure | ||
ansible.windows.win_file: | ||
path: "{{ windows_manage_iis_path }}" | ||
state: directory | ||
register: windows_manage_iis_output | ||
|
||
- name: Update Results w/win_file | ||
ansible.builtin.set_fact: | ||
windows_manage_iis_results: "{{ windows_manage_iis_results | default({}) | combine({'win_file': windows_manage_iis_output}) }}" | ||
|
||
- name: Delete Default Site | ||
community.windows.win_iis_website: | ||
name: "Default Web Site" | ||
state: absent | ||
|
||
- name: Create IIS site | ||
community.windows.win_iis_website: | ||
name: "{{ windows_manage_iis_name }}" | ||
state: started | ||
port: "{{ windows_manage_iis_port }}" | ||
physical_path: "{{ windows_manage_iis_path }}" | ||
notify: restart iis service | ||
register: windows_manage_iis_output | ||
|
||
- name: Update Results w/win_iis_website | ||
ansible.builtin.set_fact: | ||
windows_manage_iis_results: "{{ windows_manage_iis_results | default({}) | combine({'win_iis_website': windows_manage_iis_output}) }}" | ||
|
||
- name: Open port for site on the firewall | ||
community.windows.win_firewall_rule: | ||
name: "iisport{{ windows_manage_iis_port }}" | ||
enable: true | ||
state: present | ||
localport: "{{ windows_manage_iis_port }}" | ||
action: Allow | ||
direction: In | ||
protocol: Tcp | ||
register: windows_manage_iis_output | ||
|
||
- name: Update Results w/win_firewall_rule | ||
ansible.builtin.set_fact: | ||
windows_manage_iis_results: "{{ windows_manage_iis_results | default({}) | combine({'win_firewall_rule': windows_manage_iis_output}) }}" | ||
|
||
- name: Template simple web site to iis_site_path as index.html | ||
ansible.windows.win_template: | ||
src: 'index.html.j2' | ||
dest: '{{ windows_manage_iis_path }}\index.html' | ||
register: windows_manage_iis_output | ||
|
||
- name: Update Results w/win_template | ||
ansible.builtin.set_fact: | ||
windows_manage_iis_results: "{{ windows_manage_iis_results | default({}) | combine({'win_template': windows_manage_iis_output}) }}" | ||
|
||
- name: Show results | ||
ansible.builtin.debug: | ||
var: windows_manage_iis_results |
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,51 @@ | ||
--- | ||
# tasks file for windows_manage_iis/delete | ||
|
||
- name: Close port for site on the firewall | ||
community.windows.win_firewall_rule: | ||
name: "iisport{{ windows_manage_iis_port }}" | ||
state: absent | ||
register: windows_manage_iis_output | ||
|
||
- name: Update Results w/win_firewall_rule | ||
ansible.builtin.set_fact: | ||
windows_manage_iis_results: "{{ windows_manage_iis_results | default({}) | combine({'win_firewall_rule': windows_manage_iis_output}) }}" | ||
|
||
- name: Delete IIS site | ||
community.windows.win_iis_website: | ||
name: "{{ windows_manage_iis_name }}" | ||
state: absent | ||
notify: restart iis service | ||
register: windows_manage_iis_output | ||
|
||
- name: Update Results w/win_iis_website | ||
ansible.builtin.set_fact: | ||
windows_manage_iis_results: "{{ windows_manage_iis_results | default({}) | combine({'win_iis_website': windows_manage_iis_output}) }}" | ||
|
||
- name: Delete site directory structure | ||
ansible.windows.win_file: | ||
path: "{{ windows_manage_iis_path }}" | ||
state: absent | ||
register: windows_manage_iis_output | ||
|
||
- name: Update Results w/win_file | ||
ansible.builtin.set_fact: | ||
windows_manage_iis_results: "{{ windows_manage_iis_results | default({}) | combine({'win_file': windows_manage_iis_output}) }}" | ||
|
||
- name: Remove IIS Service | ||
ansible.windows.win_feature: | ||
name: Web-Server | ||
state: absent | ||
when: | ||
- windows_manage_iis_delete_option == 'all' | ||
register: windows_manage_iis_output | ||
|
||
- name: Update Results w/win_feature | ||
ansible.builtin.set_fact: | ||
windows_manage_iis_results: "{{ windows_manage_iis_results | default({}) | combine({'win_feature': windows_manage_iis_output}) }}" | ||
when: | ||
- windows_manage_iis_delete_option == 'all' | ||
|
||
- name: Show results | ||
ansible.builtin.debug: | ||
var: windows_manage_iis_results |
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,5 @@ | ||
--- | ||
# tasks file for windows_managed_iis | ||
|
||
- name: Create or delete Windows IIS server | ||
ansible.builtin.include_tasks: "{{ windows_manage_iis_operation }}.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,8 @@ | ||
<html> | ||
<body> | ||
|
||
<p align=center><img src='http://docs.ansible.com/images/logo.png' align=center> | ||
<h1 align=center>{{ windows_manage_iis_test_message }}</h1> | ||
|
||
</body> | ||
</html> |
3 changes: 3 additions & 0 deletions
3
tests/integration/targets/windows_ops_test_windows_manage_iis/aliases
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 @@ | ||
windows | ||
infra/windows | ||
role/windows_manage_iis |
6 changes: 6 additions & 0 deletions
6
tests/integration/targets/windows_ops_test_windows_manage_iis/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,6 @@ | ||
--- | ||
windows_manage_iis_name: "test-iis-server" | ||
windows_manage_iis_port: 8080 | ||
windows_manage_iis_path: "C:\\sites\\playbooktest" | ||
windows_manage_iis_feature: None | ||
windows_manage_iis_test_message: "Never gonna give you up, Never gonna let you go" |
28 changes: 28 additions & 0 deletions
28
tests/integration/targets/windows_ops_test_windows_manage_iis/tasks/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,28 @@ | ||
--- | ||
# Test: Create and Delete IIS server | ||
- name: Create IIS Server | ||
ansible.builtin.include_role: | ||
name: infra.windows_ops.windows_manage_iis | ||
vars: | ||
windows_manage_iis_operation: create | ||
|
||
# Verify that IIS Server was created as expected | ||
- name: Retrieve index.html | ||
ansible.windows.win_uri: | ||
url: "http://{{ ansible_host }}:{{ windows_manage_iis_port }}" | ||
return_content: true | ||
register: this | ||
failed_when: this is failed or windows_manage_iis_test_message not in this.content | ||
|
||
- name: Delete IIS Server | ||
ansible.builtin.include_role: | ||
name: infra.windows_ops.windows_manage_iis | ||
vars: | ||
windows_manage_iis_operation: delete | ||
|
||
# Verify that IIS Server was created as expected | ||
- name: Retrieve index.html | ||
ansible.windows.win_uri: | ||
url: "http://{{ ansible_host }}:{{ windows_manage_iis_port }}" | ||
register: this | ||
failed_when: this is not failed |