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

Query web server for port and path #8

Merged
merged 1 commit into from
Nov 26, 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
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
Loading