Ansible win_copy or win_file error "The given path's format is not supported"

I’m having a problem creating or copying files from my Ansible box to windows. Commands like reboot work fine. But any command that involves a PATH gives me this error.

My command (C&P from Ansible’s site)

  • name: Touch a file (creates if not present, updates modification time if present)
    win_file:
    path: C:\foo.conf
    state: touch

The error:

fatal: [XX.XXX.XX.112]: FAILED! => {
“failed”: true,
“msg”: “#< CLIXML\r\n<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04\”><S S="Error">Exception calling "Create" with "1" argument(s): "The given path’s format is no_x000D__x000A_<S S="Error">t supported."x000D__x000A<S S="Error">At line:6 char:31_x000D__x000A_<S S="Error">+ $fd = [System.IO.File]::Create <<<< ($path)x000D__x000A<S S="Error"> + CategoryInfo : NotSpecified: (:slight_smile: , ParentContainsErrorRecordE x000D__x000A<S S="Error"> xception_x000D__x000A_<S S="Error"> + FullyQualifiedErrorId : DotNetMethodException_x000D__x000A_<S S="Error"> x000D__x000A"
}

I’ve tried everything, uppercase drive letter, double , quotes. What am I doing wrong here?

Thanks!!

What is your file encoding of the ansible playbook/varr.. files.

Ansible run only on linux ensure files are encoded with utf8 and a new line format with "LF"

This is my playbook file. I’ve been using it no problem with the usual linux commands (ie file module). As you see, win_reboot is there, commented. That one works perfect. I only get the error when a PATH is involved. If I put the wrong path on the linux or windows (src / dest) it event tells me that it can’t find it. It seems that it is complaining about something in the windows path…

Any idea?

What version of Ansible are you on? Usually the CLIXML errors are cleaned up in the newer versions of Ansible where a lot of these paths issues have been fixed. Using a backslash without quotes or just single quotes is more than fine, I’m able to run a task like

`

  • win_copy:
    src: /tmp/file.txt
    dest: C:\temp\file.txt
    `

We have some docs around path formatting for Windows that should work from 2.2/2.3 onwards as I’ve used most of those examples in those versions http://docs.ansible.com/ansible/devel/user_guide/windows_usage.html#path-formatting-for-windows.

Thanks

Jordan

My version is ansible 2.2.1.0 and pywinrm 0.3.0 (Also tried 0.2.2 and 0.3.0b1). I am going to have a look at the link, but I am sure I’ve tried several of those variants.

Any ideas? Thanks!!

I think I might have found a potential reason for the issue! I am testing this on a VM that I’ve just created. No windows updates have been installed and I see “DotNetMethodException” as part of the error message.

fatal: [XXXXXXXXXXX]: FAILED! => {
“failed”: true,
“msg”: “#< CLIXML\r\n<Objs Version="1.1.0.1" xmlns="[http://schemas.microsoft.com/powershell/2004/04\](http://schemas.microsoft.com/powershell/2004/04\)”><S S="Error">Exception calling "Create" with "1" argument(s): "The given path’s format is no_x000D__x000A_<S S="Error">t supported."x000D__x000A<S S="Error">At line:6 char:31_x000D__x000A_<S S="Error">+ $fd = [System.IO.File]::Create <<<< ($path)x000D__x000A<S S="Error"> + CategoryInfo : NotSpecified: (:slight_smile: , ParentContainsErrorRecordE x000D__x000A<S S="Error"> xception_x000D__x000A_<S S="Error"> + FullyQualifiedErrorId : DotNetMethodExceptionx000D__x000A<S S="Error"> x000D__x000A"
}

Maybe the issue is on the Windows VM because of DotNet not being up to date. I am installing updates now. Will let you know!

Does Ansible work on a vm pool using DHCP? How do you get the hosts file to scan for addresses?

I would doubt that it is .NET but I have been wrong before :slight_smile: It is saying the exception is coming from a .NET function, in this case [System.IO.File]::Create() https://msdn.microsoft.com/en-us/library/d62kzs03(v=vs.110).aspx and it is saying the given path’s format is not supported. I would look at the encoding of your local playbook file and also check to see if there are any hidden whitespace or control characters in an around your path as that could be causing an issue. As for .NET, we support .NET 4.0 and newer which I believe is standard from Server 2012 and onwards. Older hosts need to be upgraded.

The file seems to be UTF-8:

file -i playbook/esxi.yml

playbook/esxi.yml: text/plain; charset=utf-8

I still get the same error:

fatal: [XXX.XXX.XXX.XXX]: FAILED! => {
“failed”: true,
“msg”: “#< CLIXML\r\n<Objs Version="1.1.0.1" xmlns="[http://schemas.microsoft.com/powershell/2004/04\](http://schemas.microsoft.com/powershell/2004/04\)”><S S="Error">Exception calling "Create" with "1" argument(s): "The given path’s format is no_x000D__x000A_<S S="Error">t supported."x000D__x000A<S S="Error">At line:6 char:31_x000D__x000A_<S S="Error">+ $fd = [System.IO.File]::Create <<<< ($path)x000D__x000A<S S="Error"> + CategoryInfo : NotSpecified: (:slight_smile: , ParentContainsErrorRecordE x000D__x000A<S S="Error"> xception_x000D__x000A_<S S="Error"> + FullyQualifiedErrorId : DotNetMethodException_x000D__x000A_<S S="Error"> x000D__x000A"
}

Here is some info about my system:

Python 2.7.13

ansible 2.2.1.0

pip 9.0.1

pywinrm: 0.3.0

Any ideas?

Thanks!