Ansible “;目标目录不存在”;复制模板时出错
使用以下代码复制模板时Ansible “;目标目录不存在”;复制模板时出错,ansible,Ansible,使用以下代码复制模板时 - 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
- 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使用--relative选项所做的类似,您需要首先创建目录。您可以按照与当前任务类似的方式执行此操作:
- 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'