From b6bf429a0827667e3d56e0822ebde29c849d64da Mon Sep 17 00:00:00 2001 From: Bill Peck Date: Tue, 26 Nov 2024 15:52:21 -0500 Subject: [PATCH] Query web server for port and path delete operation will query for the server and populate port and path. --- .../windows_manage_iis/meta/argument_specs.yml | 1 - roles/windows_manage_iis/tasks/delete.yml | 17 +++++++++++++++++ .../defaults/main.yml | 9 ++++----- .../tasks/main.yml | 12 +++++++++--- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/roles/windows_manage_iis/meta/argument_specs.yml b/roles/windows_manage_iis/meta/argument_specs.yml index 8951c58..8a0a90c 100644 --- a/roles/windows_manage_iis/meta/argument_specs.yml +++ b/roles/windows_manage_iis/meta/argument_specs.yml @@ -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. diff --git a/roles/windows_manage_iis/tasks/delete.yml b/roles/windows_manage_iis/tasks/delete.yml index 3739dee..7c86181 100644 --- a/roles/windows_manage_iis/tasks/delete.yml +++ b/roles/windows_manage_iis/tasks/delete.yml @@ -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 }}" diff --git a/tests/integration/targets/windows_ops_test_windows_manage_iis/defaults/main.yml b/tests/integration/targets/windows_ops_test_windows_manage_iis/defaults/main.yml index 1c68bc0..7ec22b1 100644 --- a/tests/integration/targets/windows_ops_test_windows_manage_iis/defaults/main.yml +++ b/tests/integration/targets/windows_ops_test_windows_manage_iis/defaults/main.yml @@ -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" diff --git a/tests/integration/targets/windows_ops_test_windows_manage_iis/tasks/main.yml b/tests/integration/targets/windows_ops_test_windows_manage_iis/tasks/main.yml index e2db405..c25f9b4 100644 --- a/tests/integration/targets/windows_ops_test_windows_manage_iis/tasks/main.yml +++ b/tests/integration/targets/windows_ops_test_windows_manage_iis/tasks/main.yml @@ -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