此上下文盐堆栈中不允许映射值

mapping values are not allowed in this context salt stack

无法在 salt 堆栈中的 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 语句中使用 {{ }}