【发布时间】:2019-11-10 22:13:14
【问题描述】:
我需要在远程主机上使用多个模板文件和 Jinja 的 {% block block_name %} 在我的 Ansible 角色中生成一个文件
例如,
main.conf.j2:
value1 = 123
value2 = 456
{% block test %} {% endblock %}
value3 = 789
{% block example %} {% endblock %}
value4 = abcd
test.conf.j2:
{% block test %}
more text here
{% endblock %}
example.conf.j2
{% block example %}
....
example_param = 'example!'
....
{% endblock %}
下一步是什么?我必须在 test.conf.j2 和 example.conf.j2 中使用{% extends 'nginx.conf.j2' %}?如果是这样 - 我的 Ansible 任务会怎样?还是别的什么?
如果我尝试这样的事情:
- name: Copy config
template:
src: "{{ item }}"
dest: "{{ conf_file_path }}"
with_items:
- "main.conf.j2"
- "test.conf.j2"
- "example.conf.j2"
- "abcd.conf.j2"
它仅适用于 main.conf.j2 和 test.conf.j2,但忽略 example.conf.j2 和其他模板
【问题讨论】:
标签: ansible ansible-2.x ansible-template