Skip to content

Commit

Permalink
Merge pull request #8 from p3ck/delete_fix
Browse files Browse the repository at this point in the history
Query web server for port and path
  • Loading branch information
p3ck authored Nov 26, 2024
2 parents b9add55 + b6bf429 commit 28b8cce
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
1 change: 0 additions & 1 deletion roles/windows_manage_iis/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ argument_specs:
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.
17 changes: 17 additions & 0 deletions roles/windows_manage_iis/tasks/delete.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
---
# tasks file for windows_manage_iis/delete

- name: Query Server
ansible.windows.win_powershell:
script: |
Get-Website -Name {{ windows_manage_iis_name }}
register: powershell_result

- name: Fail if server doesn't exist
ansible.builtin.fail:
msg: "{{ windows_manage_iis_name }} Doesn't exist."
when:
- powershell_result.output | length != 1

- name: Set Facts
ansible.builtin.set_fact:
windows_manage_iis_path: "{{ powershell_result.output[0].physicalPath }}"
windows_manage_iis_port: "{{ (powershell_result.output[0].bindings.Collection | regex_search(':([0-9]+):', '\\1'))[0] }}"

- name: Close port for site on the firewall
community.windows.win_firewall_rule:
name: "iisport{{ windows_manage_iis_port }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
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"
iis_name: "test-iis-server"
iis_port: 8080
iis_path: "C:\\sites\\playbooktest"
iis_test_message: "Never gonna give you up, Never gonna let you go"
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@
name: infra.windows_ops.windows_manage_iis
vars:
windows_manage_iis_operation: create
windows_manage_iis_name: "{{ iis_name }}"
windows_manage_iis_port: "{{ iis_port }}"
windows_manage_iis_path: "{{ iis_path }}"
windows_manage_iis_test_message: "{{ iis_test_message }}"

# Verify that IIS Server was created as expected
- name: Retrieve index.html
ansible.windows.win_uri:
url: "http://{{ ansible_host }}:{{ windows_manage_iis_port }}"
url: "http://{{ ansible_host }}:{{ iis_port }}"
return_content: true
register: this
failed_when: this is failed or windows_manage_iis_test_message not in this.content
failed_when: this is failed or 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
windows_manage_iis_delete_option: all
windows_manage_iis_name: "{{ iis_name }}"

# Verify that IIS Server was created as expected
- name: Retrieve index.html
ansible.windows.win_uri:
url: "http://{{ ansible_host }}:{{ windows_manage_iis_port }}"
url: "http://{{ ansible_host }}:{{ iis_port }}"
register: this
failed_when: this is not failed

0 comments on commit 28b8cce

Please sign in to comment.