ansible - 我们可以忽略ansible中内容的格式并将其写入文件吗?
问题描述
我要存储在文件中的文件内容类似于:
groups:
- name: textfile_collector_alert.rules
rules:
- alert: service_oom
expr: service_oom_file == 1
for: 1m
labels:
severity: critical
annotations:
description: 'Hprof files: {{ $labels.file }}. Reported by instance {{ $labels.instance
}} of job {{ $labels.job }}.'
summary: OOM happens
我在以下两个方面尝试了不同的形式:
但都没有奏效。
遇到同样的错误:
Error was a <class 'ansible.errors.AnsibleError'>, original message: template error while templating string: unexpected char u'$' at 213
任何帮助将不胜感激,谢谢:)
解决方案
你想要的是{% raw %}
关闭{% endraw %}
Jinja2 模板评估:
- debug:
msg: >-
{% raw %}this is some golang {{ $and can have whatever }}{% endraw %}
我相信也可以将 jinja2 转义字符从胡须上移开,但我从未亲自尝试过它有多容易(或者,当然,它是否真的有效)。
推荐阅读
- python - 无法抓取所有项目
- azure - 如何从数据块连接到 Azure SQL 并输入新数据?
- python - ValueError:运行 train.py 文件时,形状 (7, 7, 6, 64) 和 (64, 3, 7, 7) 不兼容
- python - 将多个计算列添加到数据框中的 Pythonic 方法?
- javascript - ReactJS - JSON.parse 错误:SyntaxError: Unexpected token ' in JSON at position 1
- azure-cosmosdb - Cosmos DB 选择对象的位置
- python - 如何为每个项目制作单独的评论部分
- php - 从数据库中获取价格并与动态给定的数量相乘并通过jquery显示总数
- laravel - Gitlab 显示新合并请求中的所有目标分支提交
- php - 复选框数据未存储到数据库