Repository: ansible/ansible
Pull request: Fix win_iis_virtualdirectory to remove a virtual directory that contains children
##### SUMMARY
Fix #49755 - recursive removal

##### ISSUE TYPE
- Bugfix Pull Request

##### COMPONENT NAME
win_iis_virtualdirectory.ps1

##### ADDITIONAL INFORMATION


Problem statement:
win_iis_virtualdirectory - unable to remove virtual directory with children
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
<!--- Explain the problem briefly below -->
Unable to remove IIS virtual directory

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below -->
win_iis_virtualdirectory

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
ansible 2.7.1
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below
ANSIBLE_PIPELINING(/etc/ansible/ansible.cfg) = False
ANSIBLE_SSH_CONTROL_PATH(/etc/ansible/ansible.cfg) = /tmp/%%h-%%r
DEFAULT_CALLBACK_WHITELIST(/etc/ansible/ansible.cfg) = [u'profile_tasks']
DEFAULT_GATHER_TIMEOUT(/etc/ansible/ansible.cfg) = 60
DEFAULT_STDOUT_CALLBACK(/etc/ansible/ansible.cfg) = debug
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
RETRY_FILES_ENABLED(/etc/ansible/ansible.cfg) = False
```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
Windows Server 2016

##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->
Create an IIS virtual directory with a multi-tiered folder structure (ie: UI/css, UI/img)
Run sample playbook task to remove

<!--- Paste example playbooks or commands between quotes below -->
```yaml
  - name: Remove UI Virtual Directory
    win_iis_virtualdirectory:
      name: UI
      state: absent
      site: Default Web Site
```

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
UI Virtual Directory is removed

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->
Task fails as prompt is expecting user interaction

<!--- Paste verbatim command output between quotes -->
```paste below
A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: The item at IIS:\Sites\Default Web Site\UI has children and the Recurse parameter was not specified. If you continue, all children will be removed with the item. Are you sure you want to continue?
```

##### SUGGESTED FIX
Change this:
  If ($state -eq 'absent' -and $directory) {
    Remove-Item $directory_path
    $result.changed = $true
  }

To this:
  If ($state -eq 'absent' -and $directory) {
    Remove-Item $directory_path -Recurse
    $result.changed = $true
  }

Hints from issue discussion:
Files identified in the description:
* [lib/ansible/modules/windows/win_iis_virtualdirectory.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/windows/win_iis_virtualdirectory.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @dagwieers @henrikwallstrom @jborean93 @jhawkesworth @nitzmahone
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @if-meaton
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Commit message: FIX #49755

Patch to review:
diff --git a/lib/ansible/modules/windows/win_iis_virtualdirectory.ps1 b/lib/ansible/modules/windows/win_iis_virtualdirectory.ps1
index 5d3542e3a8f600..92af7e9195032c 100644
--- a/lib/ansible/modules/windows/win_iis_virtualdirectory.ps1
+++ b/lib/ansible/modules/windows/win_iis_virtualdirectory.ps1
@@ -65,7 +65,7 @@ try {
 
   # Remove directory
   If ($state -eq 'absent' -and $directory) {
-    Remove-Item $directory_path
+    Remove-Item $directory_path -Recurse
     $result.changed = $true
   }
 
diff --git a/lib/ansible/modules/windows/win_iis_virtualdirectory.py b/lib/ansible/modules/windows/win_iis_virtualdirectory.py
index e5505e78aa4901..6f4e430af54d2e 100644
--- a/lib/ansible/modules/windows/win_iis_virtualdirectory.py
+++ b/lib/ansible/modules/windows/win_iis_virtualdirectory.py
@@ -24,6 +24,7 @@
   state:
     description:
       - Whether to add or remove the specified virtual directory.
+      - removing will remove the virtual directory and all under it (Recursively)
     type: str
     choices: [ absent, present ]
     default: present


Code review comments:
diff_hunk: @@ -65,7 +65,7 @@ try {
 
   # Remove directory
   If ($state -eq 'absent' -and $directory) {
-    Remove-Item $directory_path
+    Remove-Item $directory_path -Recurse
path: lib/ansible/modules/windows/win_iis_virtualdirectory.ps1
text: @user1:
Should also include `-Force` in case there are any hidden or read only files in the directory.