执行模板复制时出现"目标目录不存在"错误



使用以下代码复制模板时

- name: "Template source files to temp directory"
template:
src: '{{ item.src }}'
dest: '{{ temp_file_path.path }}/{{ item.path }}'
force: yes
with_filetree: "{{ nginx_path }}/"
delegate_to: 127.0.0.1
when: item.state == 'file' 

我被标题中的错误击中了。我从这里得到了一个可能的解决方案,但这里的问题是需要知道所有子目录的名称。当您遇到数十个时,这是不可能的。

解决这个问题的正确方法是什么。类似于 rysnc 对 - -相对选项所做的操作

您需要先创建目录。您可以按照与当前任务类似的方式执行此操作:

- name: "Template source files to temp directory"
file:
path: '{{ temp_file_path.path }}/{{ item.path }}'
state: directory
with_filetree: "{{ nginx_path }}/"
delegate_to: 127.0.0.1
when: item.state == 'directory'

最新更新