Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validated role windows_manage_iis #1

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions roles/windows_manage_iis/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# defaults file for
windows_manage_iis_operation: create
7 changes: 7 additions & 0 deletions roles/windows_manage_iis/handlers/main.yml
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
36 changes: 36 additions & 0 deletions roles/windows_manage_iis/meta/argument_specs.yml
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.
69 changes: 69 additions & 0 deletions roles/windows_manage_iis/tasks/create.yml
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
51 changes: 51 additions & 0 deletions roles/windows_manage_iis/tasks/delete.yml
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
5 changes: 5 additions & 0 deletions roles/windows_manage_iis/tasks/main.yml
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"
8 changes: 8 additions & 0 deletions roles/windows_manage_iis/templates/index.html.j2
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
windows
infra/windows
role/windows_manage_iis
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"
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
Loading