【发布时间】:2015-06-03 01:45:17
【问题描述】:
我想通过以下方式使用 Ansible 部署一些配置文件:
- name: Deploying test configuration
template: src={{ item }}.j2 dest={{ basho_bench_home_dir }}/conf/{{ item }}
sudo: yes
with_items:
- http_fix_1min.conf.template
- http_max_1min.conf
文件有这样的行:
{mode, max}.
{duration, 1}.
{concurrent, 32}.
这最终会破坏 J2 渲染:
fatal: [192.168.99.135] => {'msg': "AnsibleError: file: roles/basho_bench/templates/http_fix_1min.conf.template.j2, line number: 24, error: expected token 'end of print statement', got 'Content'", 'failed': True}
fatal: [192.168.99.135] => {'msg': 'One or more items failed.', 'failed': True, 'changed': False, 'results': [{'msg': "AnsibleError: file: roles/basho_bench/templates/http_fix_1min.conf.template.j2, line number: 24, error: expected token 'end of print statement', got 'Content'", 'failed': True}]}
我不确定如何告诉 J2 将模板作为大字符串处理。正如文档所建议的那样,我已经尝试过 {{' '}} 。它现在确实起作用了。
【问题讨论】:
-
你能分享你的
http_fix_1min.conf.template.j2文件吗? -
我在您的配置文件中没有看到任何模板。你为什么用
template而不是copy? -
您发布的文件的扩展名是
.erl而不是 j2。所以在我看来,您的模板文件中没有 j2 内容,因此请使用阿利克所说的copy而不是template,后者只会将src复制到dest。或者您是否在“模板”中使用了一些变量?如果是这样,那么您就在正确的轨道上,请阅读 J2 文档,而不是 ansible。 -
是的,我认为副本很好。现在问题来了,如果我需要这些文件作为模板会发生什么,因为我想更改内容。