我们有一个场景,我们必须用另一个模板文件填充最后的模板文件。
概念参考信息保存在CSV文件中,该文件获取联系人和升级点的详细信息。
#csv
incident_type,support_team,support_email
server_down,linux_group,linux@sample.com
server_crash,vmware_group,vm@sample.com然后,这必须填充一个contacts_details模板。联系人小组的模板如下所示
#contacts_details.template.j2
| Item | Value |
|---|---|
| incident_type | {{incident_type}} |
| support_team | {{support_team}} |
| support_email | {{support_email}} |然后,这个模板对象必须填充操作的主Playbook以调用
#callout.playbook.j2
some stuff already there
{{contacts_details}}因此,最终的目的是让不可接受的
{{contacts_details}}中的
我已经使用Ansible模板模块轻松地填充了模板
- name: filltemplates contacts_details
template:
src: contacts_details.template.j2
dest: contacts_details.template
- name: filltemplates callout
template:
src: callout.playbook.j2
dest: callout.playbook但是它在“标注”上失败了,因为它不能替换{{contacts_details}}
无论如何,我可以确保第一个模板迭代被持久化到第二个模板替换吗?
对于server_down类型警报,预期的最终结果是:
#My Nice Playbook
some stuff already there
| Item | Value |
|---|---|
| incident_type | server_down |
| support_team | linux_group |
| support_email | linux@sample.com |发布于 2020-10-03 08:45:21
如下所示
---
- name: Read a template and Put into another template
hosts: localhost
gather_facts: no
tasks:
- name: "show templating results"
set_fact:
contact_details: "{{ lookup('template', './templates/04_contact_details.j2') }}"
vars:
name: "bob"
email: "bob@bob.com"
phone: "12345"
- name: "Update final template"
template:
src: "./templates/04_main_callout.md.j2"
dest: "/tmp/main_callout.md"
mode: preserve模板的位置
04_contact_details.j2
| Key | Value |
|---|---|
| name | {{name}} |
| email | {{email}} |
| phone | {{phone}} |主要模板是
04_main_callout.md.j2
# Sample markdown
## aim is to fill up contact details automatically from another template
{{contact_details}}https://stackoverflow.com/questions/64156085
复制相似问题