在Ansible中,Jinja模板默认将"dest"视为文件而不是目录。如果要将"dest"视为目录,可以使用以下解决方法:
- name: Copy template file to a directory
template:
src: /path/to/template.j2
dest: /path/to/destination/
force: yes
- name: Copy template file to a directory
template:
src: /path/to/template.j2
dest: "{{ '/path/to/destination/' + (dest | dirname) }}"
通过使用以上两种方法之一,可以将"dest"视为目录而不是文件,并将目标文件复制到指定的目录中。