该template
模块本身运行在单个文件的操作,但你可以使用with_filetree
递归在指定的路径循环:
- name: Ensure directory structure exists
file:
path: '{{ templates_destination }}/{{ item.path }}'
state: directory
with_filetree: '{{ templates_source }}'
when: item.state == 'directory'
- name: Ensure files are populated from templates
template:
src: '{{ item.src }}'
dest: '{{ templates_destination }}/{{ item.path }}'
with_filetree: '{{ templates_source }}'
when: item.state == 'file'
对于单个目录中的模板,你可以使用with_fileglob
。
这个答案是无用的,这个答案太棒了!我已经添加了我自己的答案来解释原因(但是已经接受了)
当计划达成时,我会喜欢的!