
Ich habe eine Aufgabe:
- name: copy files
copy:
src: "c:\\path\\to\\dir{{ item | replace('/','\\') }}"
dest: "/tmp/{{ item }}"
with_items:
- "{{ paths }}"
Ich habe auch Folgendes versucht:, replace(\"/\",\"\\\")
aber replace(\"/\",\"\\\\\")
nichts funktioniert, irgendjemand Hilfe?
paths
enthält: project/folder1/bin
, project/folder2/bin
, usw...
Antwort1
Sie können Probleme mit Anführungszeichen vermeiden, indem Sie eine Variable mit einem Backslash als Wert definieren:
- name: copy files
copy:
src: "c:\\path\\to\\dir\\{{ item | replace('/', backslash) }}"
dest: "/tmp/{{ item }}"
vars:
backslash: "\\"
with_items:
- "{{ paths }}"