Escape space in Windows directory path in playbook

2,785 views
Skip to first unread message

Tim

unread,
Nov 2, 2016, 11:52:54 AM11/2/16
to Ansible Project
Hi,

I want to copy some files to the Startup folder using "win_copy". The problem is, that the destination directory is
"dest=C:/ProgramData/Microsoft/Windows/Start Menu/Programs/StartUp/link.lnk" which has a space between "Start" and "Menu".
I tried to escape that with quotation marks, but that didn't work. Is there another way to escape space?

Thanks,
Tim

trey perrone

unread,
Nov 2, 2016, 3:33:33 PM11/2/16
to Ansible Project
First check your version of Ansible as some older version may have had some bugs with spaces in paths. 

I'd think you need to quote around the path itself. using strict yaml i think ive done it

dest: 'C:\Documents and Settings\All Users\Start Menu\Windows Update.lnk'

or if you go with doublequotes, i think you may need doublslashes like 

dest: "C:\\Documents and Settings\\All Users\\Start Menu\\Windows Update.lnk'"

Mike Fennemore

unread,
Nov 3, 2016, 6:16:06 AM11/3/16
to Ansible Project
Alternatively use 8.3 DOS Format as the path.

Matt Davis

unread,
Nov 3, 2016, 11:26:26 AM11/3/16
to Ansible Project
Stick to YAML syntax instead of Ansible key=value syntax and you don't have to quote or escape at all:

- win_copy
    src: somelocalfile.bin
    dest: c:\windows\somelocalfile.bin

If you're in a situation where you need to quote, YAML single-quotes are also escape-free. Double-quoting allows escape characters, which means you'll either need to double your backslashes or switch to forward slashes (*most* modules are OK with this, but there are a handful that fix the paths up correctly).

-Matt

Tim

unread,
Nov 9, 2016, 11:45:21 AM11/9/16
to Ansible Project
Thanks, your solution worked. I changed the key/value syntax to the YAML syntax like you did in your example.
Reply all
Reply to author
Forward
0 new messages