yaml - 此上下文盐堆栈中不允许映射值
问题描述
无法在盐堆栈中的 for 循环下分配变量
{% set prli = ['httpd','rhnsd'] %}
{% for usr in prli %}
{% set pro = salt['cmd.shell'](' ps -eaf | grep -i {{ usr }} | wc -l') %}
{{ usr }}:
cmd.run:
- name: echo "{{ usr }} {{ pro }}"
{% endfor %}
~
出错
数据编译失败:
Rendering SLS 'failed: mapping values are not allowed in this context
解决方案
{% set prli = ['httpd','rhnsd'] %}
{% for usr in prli %}
{% set pro = salt['cmd.shell']('ps -eaf | grep -i' ~ usr ~ '| wc -l') %}
{{ usr }}:
cmd.run:
- name: echo "{{ usr }} {{ pro }}"
{% endfor %}
您不能{{ }}
在 jinja 语句中使用。
推荐阅读
- python - 如何使用 Django 在请求之间持久化数据
- python - 使用 pywin32 找出 com 对象的 ProgID
- c# - 递增 t2 变量
- html - 如何获取传递给两个不同函数的文本框的值
- xamarin - Xamarin - 迁移到 AndroidX 后恢复包失败
- mysql - 将数据 infile 加载到特定列中
- regex - 正则表达式:获取特定大写字母之间的文本
- r - 当 TRUE 在 R 中的单独向量中的相同位置时,如何创建一个重复值的序列?
- session-cookies - 从 CCAvenue 支付网关重定向时 ASP.NET 丢失会话
- typescript - TypeGraphQL:metadataDesignType = reflectType [parameterIndex] TypeError:无法读取未定义的属性“0”