如何在pythonj2模板中使用Erlang配置文件?

2024-05-16 09:37:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用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

文件的行如下:

^{pr2}$

这最终会破坏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将模板作为一个巨大的字符串来处理。我已经尝试了{{'}},正如文档所示。它现在起作用了。在


Tags: truehttpconfitemstemplatemsgitemfix
1条回答
网友
1楼 · 发布于 2024-05-16 09:37:54

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

在你可以覆盖Jinja2环境设置之前

#jinja2: variable_end_string: [[, variable_start_string: ]] 

使{{ }}不被视为标记。由于一些安全问题,Ansible开发人员禁用了此功能。现在还没有。Gihub上的相关issie是here。关注参考问题,并在讨论特性时提出请求。在

相关问题 更多 >