kay*_*kay 12 jinja2 ansible ansible-template
有没有办法将Ansible模板呈现出来?我试图找到一个解决方案但它看起来像临时文件是唯一的方法.
tec*_*raf 26
我想你可能只是在寻找template查找插件:
- set_fact:
rendered_template: "{{ lookup('template', './template.j2') }}"
Run Code Online (Sandbox Code Playgroud)
用法示例:
template.j2
Hello {{ value_for_template }}
Run Code Online (Sandbox Code Playgroud)playbook.yml
---
- hosts: localhost
gather_facts: no
connection: local
vars:
value_for_template: world
tasks:
- set_fact:
rendered_template: "{{ lookup('template', './template.j2') }}"
- debug:
var: rendered_template
Run Code Online (Sandbox Code Playgroud)结果:
TASK [debug] *******************************************************************
ok: [localhost] => {
"rendered_template": "Hello world\n"
}
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
7673 次 |
| 最近记录: |