Мне нужно скопировать файл в несколько директорий по списку, но только в те директории, которые реально существуют на диске.Я пытаюсь сделать через when:
- name: Копирование индексной страницы во все каталоги документации
copy:
src: "{{ gitReposPath }}/doxygen_documentation/idk2/html/rootindex.html"
dest: "{{ gitReposPath }}/doxygen_documentation/{{ item[gitTable_DirectoryName] }}/html/rootindex.html"
remote_src: yes
when: "{{ gitReposPath }}/doxygen_documentation/{{ item[gitTable_DirectoryName] }}/html/" | is_dir
with_items:
- "{{ gitRepos }}"
Но когда добавляю строку с when, то появляется ошибка:
ERROR! Syntax Error while loading YAML.
did not find expected comment or line breakThe error appears to be in '/home/xi/work/develop/cpp/surfProjects/iksProjects/iks_ansible_script/level0002-iksCdBuild/step0180-generateDoc.plb.yml': line 51, column 97, but may
be elsewhere in the file depending on the exact syntax problem.The offending line appears to be:
remote_src: yes
when: "{{ gitReposPath }}/doxygen_documentation/{{ item[gitTable_DirectoryName] }}/html/" | is_dir
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:with_items:
- {{ foo }}Should be written as:
with_items:
- "{{ foo }}"
Как еще можно сделать копирование? Да, я знаю что можно отключить ошибку failed_when: false, но так делать не хотелось бы.
Как выглядит gitRepos ?
Если я правильно понял задачу, то как то так
- name: Копирование индексной страницы во все каталоги документации
copy:
src: "{{ gitReposPath }}/doxygen_documentation/idk2/html/rootindex.html"
dest: "{{ gitReposPath }}/doxygen_documentation/{{ item['gitTable_DirectoryName'] }}/html/rootindex.html"
remote_src: yes
when: (gitReposPath + "/doxygen_documentation/" + item['gitTable_DirectoryName'] + "/html/") is directory
loop:
- "{{ gitRepos }}"
Только не совсем понятно, откуда у словаря который передается в loop вдруг появился атрибут - item[gitTable_DirectoryName] ?
> Как выглядит gitRepos ?по мне так не очень https://www.opennet.me/openforum/vsluhforumID1/97576.html