Escape space in Windows directory path in playbook

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

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’”

Alternatively use 8.3 DOS Format as the path.

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

Thanks, your solution worked. I changed the key/value syntax to the YAML syntax like you did in your example.