Warm tip: This article is reproduced from serverfault.com, please click

ansible-模板模块可以处理多个模板/目录吗?

(ansible - Can the templates module handle multiple templates / directories?)

发布于 2017-01-16 00:21:34

我相信Ansible复制模块可以获取一大堆“文件”,并一键复制。我相信可以通过递归复制目录来实现。

Ansible模板模块可以采用一整套“模板”并将它们一次部署吗?是否存在部署模板文件夹并递归应用模板的事情?

Questioner
danday74
Viewed
0
techraf 2017-01-16 09:24:18

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