如何使用带有 Python J2 模板的 Erlang 配置文件?

How to use Erlang configuration files with Python J2 template?

我想通过以下方式使用 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 将模板作为一个巨大的字符串来处理。我已经按照文档的建议尝试了 {{' '}} 。现在它确实起作用了。

使用 {% raw %}/{% endraw %} 块作为 Jinja2 文档 suggests

在您可以通过放置

来覆盖 Jinja2 环境设置之前
#jinja2: variable_end_string: [[, variable_start_string: ]] 

在模板文件的第一行,这样 {{ }} 就不会被视为标签。由于一些安全问题,Ansible 开发人员已禁用此功能。现在它仍然不可用。 Gihub 上的相关 issie 是 here。关注参考问题和有关该功能讨论的拉取请求。