我有一个任务:
- name: copy files
copy:
src: "c:\\path\\to\\dir{{ item | replace('/','\\') }}"
dest: "/tmp/{{ item }}"
with_items:
- "{{ paths }}"
我也尝试过:replace(\"/\",\"\\\")
,replace(\"/\",\"\\\\\")
但没有任何作用,有什么帮助吗?
paths
包含:project/folder1/bin
,,project/folder2/bin
等等...
答案1
您可以通过定义一个以反斜杠作为其值的变量来避免引号问题:
- name: copy files
copy:
src: "c:\\path\\to\\dir\\{{ item | replace('/', backslash) }}"
dest: "/tmp/{{ item }}"
vars:
backslash: "\\"
with_items:
- "{{ paths }}"