ansible / ansible-modules-core

Ansible modules - these modules ship with ansible
1.3k stars 1.95k forks source link

win_file fails to remove directory #3204

Closed michaelluich closed 8 years ago

michaelluich commented 8 years ago
Issue Type:

win_file

Ansible Version:
ansible 2.0.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
Ansible Configuration:

default config

Environment:

running on OS X El Capitan 10.11.3 Target windows 2012 R2

Summary:

win_file errors out trying to remove the directory c:\Users\testx

"Illegal characters in path."

Steps To Reproduce:

create the directory c:\Users\testx on the server.

run play below


---
- name: Update terminal servers 
  hosts: eduTs
  gather_facts: false
  tasks:
    - name: Delete test Folders
      win_file: path=c state=absent
Expected Results:

Removal of the directory c:\Users\testx and subdirectories.

Actual Results:

Ansible errors out and the directory remains.

ansible-playbook win_file.yml -vvv
Using /etc/ansible/ansible.cfg as config file
1 plays in win_file.yml

PLAY [Update terminal servers] *************************************************

TASK [Delete test Folders] *****************************************************
task path: /Users/michaelluich/playbooks/win_file.yml:6
<10.97.200.7> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO 10.97.200.7
<10.97.200.7> EXEC Set-StrictMode -Version Latest
(New-Item -Type Directory -Path $env:temp -Name "ansible-tmp-1457465127.97-39956265605103").FullName | Write-Host -Separator '';
<10.97.200.7> PUT "/var/folders/tn/f1myyd0102lggdzvsr7fgcch0000gr/T/tmp3FQnua" TO "C:\Users\ansible\AppData\Local\Temp\ansible-tmp-1457465127.97-39956265605103\win_file.ps1"
<10.97.200.7> EXEC Set-StrictMode -Version Latest
Try
{
& "C:\Users\ansible\AppData\Local\Temp\ansible-tmp-1457465127.97-39956265605103\win_file.ps1"
}
Catch
{
$_obj = @{ failed = $true }
If ($_.Exception.GetType)
{
$_obj.Add('msg', $_.Exception.Message)
}
Else
{
$_obj.Add('msg', $_.ToString())
}
If ($_.InvocationInfo.PositionMessage)
{
$_obj.Add('exception', $_.InvocationInfo.PositionMessage)
}
ElseIf ($_.ScriptStackTrace)
{
$_obj.Add('exception', $_.ScriptStackTrace)
}
Try
{
$_obj.Add('error_record', ($_ | ConvertTo-Json | ConvertFrom-Json))
}
Catch
{
}
Echo $_obj | ConvertTo-Json -Compress -Depth 99
Exit 1
}
Finally { Remove-Item "C:\Users\ansible\AppData\Local\Temp\ansible-tmp-1457465127.97-39956265605103" -Force -Recurse -ErrorAction SilentlyContinue }
An exception occurred during task execution. The full traceback is:
At C:\Users\ansible\AppData\Local\Temp\ansible-tmp-1457465127.97-39956265605103\win_file.ps1:292 char:5
+ If (Test-Path $path)
+     ~~~~~~~~~~~~~~~
fatal: [10.97.200.7]: FAILED! => {"changed": false, "error_record": {"CategoryInfo": {"Activity": "Test-Path", "Category": 5, "Reason": "ArgumentException", "TargetName": "C:\\Users\testx", "TargetType": "String"}, "ErrorDetails": null, "Exception": {"Data": {}, "HResult": -2147024809, "HelpLink": null, "InnerException": null, "Message": "Illegal characters in path.", "ParamName": null, "Source": "mscorlib", "StackTrace": "   at System.IO.Path.GetFileName(String path)\r\n   at Microsoft.PowerShell.Commands.FileSystemProvider.IsReservedDeviceName(String destinationPath)\r\n   at Microsoft.PowerShell.Commands.FileSystemProvider.NativeItemExists(String path, Boolean& directory)\r\n   at Microsoft.PowerShell.Commands.FileSystemProvider.ItemExists(String path, ErrorRecord& error)", "TargetSite": {"Attributes": 150, "CallingConvention": 1, "ContainsGenericParameters": false, "CustomAttributes": "[__DynamicallyInvokableAttribute()]", "DeclaringType": "System.IO.Path", "IsAbstract": false, "IsAssembly": false, "IsConstructor": false, "IsFamily": false, "IsFamilyAndAssembly": false, "IsFamilyOrAssembly": false, "IsFinal": false, "IsGenericMethod": false, "IsGenericMethodDefinition": false, "IsHideBySig": true, "IsPrivate": false, "IsPublic": true, "IsSecurityCritical": false, "IsSecuritySafeCritical": false, "IsSecurityTransparent": true, "IsSpecialName": false, "IsStatic": true, "IsVirtual": false, "MemberType": 8, "MetadataToken": 100681632, "MethodHandle": "System.RuntimeMethodHandle", "MethodImplementationFlags": 0, "Module": "CommonLanguageRuntimeLibrary", "Name": "GetFileName", "ReflectedType": "System.IO.Path", "ReturnParameter": "System.String ", "ReturnType": "string", "ReturnTypeCustomAttributes": "System.String "}}, "FullyQualifiedErrorId": "ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand", "InvocationInfo": {"BoundParameters": {}, "CommandOrigin": 1, "DisplayScriptPosition": null, "ExpectingInput": false, "HistoryId": 1, "InvocationName": "Test-Path", "Line": "If (Test-Path $path)\n", "MyCommand": {"CommandType": 8, "DefaultParameterSet": "Path", "Definition": "\r\nTest-Path [-Path] <string[]> [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-PathType <TestPathType>] [-IsValid] [-Credential <pscredential>] [-UseTransaction] [<CommonParameters>]\r\n\r\nTest-Path -LiteralPath <string[]> [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-PathType <TestPathType>] [-IsValid] [-Credential <pscredential>] [-UseTransaction] [<CommonParameters>]\r\n", "HelpFile": "Microsoft.PowerShell.Commands.Management.dll-Help.xml", "ImplementingType": "Microsoft.PowerShell.Commands.TestPathCommand", "Module": "Microsoft.PowerShell.Management", "ModuleName": "Microsoft.PowerShell.Management", "Name": "Test-Path", "Noun": "Path", "Options": 1, "OutputType": "System.Boolean", "PSSnapIn": null, "ParameterSets": "[-Path] <string[]> [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-PathType <TestPathType>] [-IsValid] [-Credential <pscredential>] [-UseTransaction] [<CommonParameters>] -LiteralPath <string[]> [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-PathType <TestPathType>] [-IsValid] [-Credential <pscredential>] [-UseTransaction] [<CommonParameters>]", "Parameters": "System.Collections.Generic.Dictionary`2[System.String,System.Management.Automation.ParameterMetadata]", "RemotingCapability": 1, "Verb": "Test", "Visibility": 0}, "OffsetInLine": 5, "PSCommandPath": "C:\\Users\\ansible\\AppData\\Local\\Temp\\ansible-tmp-1457465127.97-39956265605103\\win_file.ps1", "PSScriptRoot": "C:\\Users\\ansible\\AppData\\Local\\Temp\\ansible-tmp-1457465127.97-39956265605103", "PipelineLength": 0, "PipelinePosition": 0, "PositionMessage": "At C:\\Users\\ansible\\AppData\\Local\\Temp\\ansible-tmp-1457465127.97-39956265605103\\win_file.ps1:292 char:5\r\n+ If (Test-Path $path)\r\n+     ~~~~~~~~~~~~~~~", "ScriptLineNumber": 292, "ScriptName": "C:\\Users\\ansible\\AppData\\Local\\Temp\\ansible-tmp-1457465127.97-39956265605103\\win_file.ps1", "UnboundArguments": []}, "PSMessageDetails": null, "PipelineIterationInfo": [], "ScriptStackTrace": "at <ScriptBlock>, C:\\Users\\ansible\\AppData\\Local\\Temp\\ansible-tmp-1457465127.97-39956265605103\\win_file.ps1: line 292\r\nat <ScriptBlock>, <No file>: line 4", "TargetObject": "C:\\Users\testx"}, "failed": true, "invocation": {"module_name": "win_file"}, "msg": "Illegal characters in path."}

NO MORE HOSTS LEFT *************************************************************
    to retry, use: --limit @win_file.retry

PLAY RECAP *********************************************************************
jhawkesworth commented 8 years ago

I suspect the \t or \U is getting interpreted as an escape sequence instead of a path - the TargetObject in the output looks like this: "TargetObject": "C:\Users\testx" which is a strange looking path (mix of \ and \ as path separators).

Your reproducer playbook looks like it would fail anyway as I imagine path=c is not a valid path.

I suggest trying the following:

win_file: "path=c:\Users\testx state=absent"

or use the yaml style syntax.

win_file: path: C:\Users\testx state: absent

michaelluich commented 8 years ago

The non yaml version win_file: "path=c:\Users\testx state=absent" failed with the same error "Illegal characters in path."

The yaml version worked as expected.

Failure:

- name: Delete test Folders
  win_file: "path=c:\Users\testx" state=absent

TASK [Delete test Folders]


An exception occurred during task execution. To see the full traceback, use -vvv. The error was: + ~~~ fatal: [10.97.200.7]: FAILED! => {"changed": false, "error_record": {"CategoryInfo": {"Activity": "Test-Path", "Category": 5, "Reason": "ArgumentException", "TargetName": "C:\Users\testx", "TargetType": "String"}, "ErrorDetails": null, "Exception": {"Data": {}, "HResult": -2147024809, "HelpLink": null, "InnerException": null, "Message": "Illegal characters in path.", "ParamName": null, "Source": "mscorlib", "StackTrace": " at System.IO.Path.GetFileName(String path)\r\n at Microsoft.PowerShell.Commands.FileSystemProvider.IsReservedDeviceName(String destinationPath)\r\n at Microsoft.PowerShell.Commands.FileSystemProvider.NativeItemExists(String path, Boolean& directory)\r\n at Microsoft.PowerShell.Commands.FileSystemProvider.ItemExists(String path, ErrorRecord& error)", "TargetSite": {"Attributes": 150, "CallingConvention": 1, "ContainsGenericParameters": false, "CustomAttributes": "[__DynamicallyInvokableAttribute()]", "DeclaringType": "System.IO.Path", "IsAbstract": false, "IsAssembly": false, "IsConstructor": false, "IsFamily": false, "IsFamilyAndAssembly": false, "IsFamilyOrAssembly": false, "IsFinal": false, "IsGenericMethod": false, "IsGenericMethodDefinition": false, "IsHideBySig": true, "IsPrivate": false, "IsPublic": true, "IsSecurityCritical": false, "IsSecuritySafeCritical": false, "IsSecurityTransparent": true, "IsSpecialName": false, "IsStatic": true, "IsVirtual": false, "MemberType": 8, "MetadataToken": 100681632, "MethodHandle": "System.RuntimeMethodHandle", "MethodImplementationFlags": 0, "Module": "CommonLanguageRuntimeLibrary", "Name": "GetFileName", "ReflectedType": "System.IO.Path", "ReturnParameter": "System.String ", "ReturnType": "string", "ReturnTypeCustomAttributes": "System.String "}}, "FullyQualifiedErrorId": "ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand", "InvocationInfo": {"BoundParameters": {}, "CommandOrigin": 1, "DisplayScriptPosition": null, "ExpectingInput": false, "HistoryId": 1, "InvocationName": "Test-Path", "Line": "If (Test-Path $path)\n", "MyCommand": {"CommandType": 8, "DefaultParameterSet": "Path", "Definition": "\r\nTest-Path [-Path] <string[]> [-Filter ] [-Include <string[]>] [-Exclude <string[]>] [-PathType ] [-IsValid] [-Credential ] [-UseTransaction] []\r\n\r\nTest-Path -LiteralPath <string[]> [-Filter

] [-Include ] [-Exclude ] [-PathType ] [-IsValid] [-Credential ] [-UseTransaction] []\r\n", "HelpFile": "Microsoft.PowerShell.Commands.Management.dll-Help.xml", "ImplementingType": "Microsoft.PowerShell.Commands.TestPathCommand", "Module": "Microsoft.PowerShell.Management", "ModuleName": "Microsoft.PowerShell.Management", "Name": "Test-Path", "Noun": "Path", "Options": 1, "OutputType": "System.Boolean", "PSSnapIn": null, "ParameterSets": "[-Path] [-Filter ] [-Include ] [-Exclude ] [-PathType ] [-IsValid] [-Credential ] [-UseTransaction] [] -LiteralPath [-Filter ] [-Include ] [-Exclude ] [-PathType ] [-IsValid] [-Credential ] [-UseTransaction] []", "Parameters": "System.Collections.Generic.Dictionary`2[System.String,System.Management.Automation.ParameterMetadata]", "RemotingCapability": 1, "Verb": "Test", "Visibility": 0}, "OffsetInLine": 5, "PSCommandPath": "C:\Users\ansible\AppData\Local\Temp\ansible-tmp-1457536782.19-126224063740564\win_file.ps1", "PSScriptRoot": "C:\Users\ansible\AppData\Local\Temp\ansible-tmp-1457536782.19-126224063740564", "PipelineLength": 0, "PipelinePosition": 0, "PositionMessage": "At C:\Users\ansible\AppData\Local\Temp\ansible-tmp-1457536782.19-126224063740564\win_file.ps1:292 char:5\r\n+ If (Test-Path $path)\r\n+ ~~~~~~~~~~~~~~~", "ScriptLineNumber": 292, "ScriptName": "C:\Users\ansible\AppData\Local\Temp\ansible-tmp-1457536782.19-126224063740564\win_file.ps1", "UnboundArguments": []}, "PSMessageDetails": null, "PipelineIterationInfo": [], "ScriptStackTrace": "at , C:\Users\ansible\AppData\Local\Temp\ansible-tmp-1457536782.19-126224063740564\win_file.ps1: line 292\r\nat , : line 4", "TargetObject": "C:\Users\testx"}, "failed": true, "msg": "Illegal characters in path."} NO MORE HOSTS LEFT --- to retry, use: --limit @win_file.retry PLAY RECAP --- 10.97.200.7 : ok=0 changed=0 unreachable=0 failed=1 Success: ``` - name: Delete test Folders win_file: path: C:\Users\testx state: absent ``` ansible-playbook win_file.yml PLAY [Update terminal servers] --- TASK [Delete test Folders] --- changed: [10.97.200.7] PLAY RECAP --- 10.97.200.7 : ok=1 changed=1 unreachable=0 failed=0 michaelluich:playbooks michaelluich$ On Wed, Mar 9, 2016 at 10:07 AM, jhawkesworth notifications@github.com wrote: > I suspect the \t or \U is getting interpreted as an escape sequence > instead of a path - the TargetObject in the output looks like this: > "TargetObject": "C:\Users\testx" which is a strange looking path (mix of \ > and \ as path separators). > > Your reproducer playbook looks like it would fail anyway as I imagine > path=c is not a valid path. > > I suggest trying the following: > > win_file: "path=c:\Users\testx state=absent" > > or use the yaml style syntax. > > win_file: > path: C:\Users\testx > state: absent > > — > Reply to this email directly or view it on GitHub > https://github.com/ansible/ansible-modules-core/issues/3204#issuecomment-194336554 > . ## http://www.actifio.com/ _Michael Luich__Senior DevOps *_Engineer* _e_ michael.luich@actifio.com _h_ helpdesk@actifio.com _p_ 603.475.5799 333 Wyman Street, Waltham, MA 02451 http://twitter.com/actifio http://www.linkedin.com/company/399246 https://plus.google.com/102870897962348937868/posts http://www.youtube.com/user/actifio http://www.actifio.com/ _Manage, access, and protect your data with a single platform that saves you time, money, and complexity._
jhawkesworth commented 8 years ago

yaml style is generally preferred where possible now I believe.

ansibot commented 8 years ago

@jhawkesworth, ping. This issue is still waiting on your response. click here for bot help

jhawkesworth commented 8 years ago

This bug report is old, and the correct way to form paths for windows hosts is described above, so I am going to close this. If there is more to add @michaelluich please re-open, but this looks like an answered question to me.