如何在Yaml中连接几个字符串和变量?

时间:2014-06-07 05:56:36

标签: yaml ansible ansible-playbook

我需要做这样的事情:

domain: &domain example.com
ip: &ip 1.2.3.4
Address4: v=spf1 include:*domain ip4:*ip -all

我试过这个但是没有用,它说有语法错误:

Address4: 'v=spf1 include:'*domain' ip4:'*ip' -all'

实现(我在Ansible中使用这些文件)似乎支持连接,例如这样可以正常工作:

Address2: http://*domain # actually this doesn't work, I don't remember the exact example

有什么想法吗?

1 个答案:

答案 0 :(得分:-2)

由于Ansible使用jinja2作为模板引擎,因此我不能完全理解您为什么要在YAML中进行连接:

在Ansible的vars文件中定义变量(在YAML中):

domain: example.com
ip: 1.2.3.4

引用变量(仍在YAML中):

Address4: v=spf1 include:{{ domain }} ip4:{{ ip }} -all

当您在模板模块中使用Address4变量时(我假设),它的工作方式相同。

相关问题