【问题标题】:“Destination directory does not exist” error while doing template copying进行模板复制时出现“目标目录不存在”错误
【发布时间】:2023-03-27 14:20:01
【问题描述】:

使用以下代码复制模板时

- 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' 

我被标题中的错误击中了。 I got a possible solution from here 但这里的问题是需要知道所有子目录的名称。当您遇到数十个时,这是不可能的。

解决这个问题的正确方法是什么。类似于 rysnc 使用 - -relative 选项所做的事情

【问题讨论】:

    标签: ansible


    【解决方案1】:

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

    - 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'
    

    【讨论】:

      猜你喜欢
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 2012-09-10
      • 2016-04-24
      • 2019-12-24
      • 2018-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多