在Ansible中,可以使用模板引擎来使用变量和字符串。下面是一个示例:
template.j2
的模板文件,内容如下:Hello, {{ name }}!
template
模块来渲染模板文件,并传递变量的值。示例如下:- name: Render template
hosts: localhost
gather_facts: false
vars:
name: "John"
tasks:
- name: Render template
template:
src: template.j2
dest: /path/to/output/file
在上述示例中,name
变量的值为"John",它将会在模板文件中被替换为"John"。渲染的结果将会保存到/path/to/output/file
文件中。
/path/to/output/file
,内容如下:Hello, John!
这就是使用Ansible模板引擎来使用变量和字符串的示例。你可以根据自己的需求来编写模板文件和传递变量的值。