【问题标题】:Rendering SLS: mapping values are not allowed here渲染 SLS:此处不允许映射值
【发布时间】:2019-05-06 15:22:19
【问题描述】:

我尝试根据 PILLAR 变量在配置文件中放置/删除一个下拉菜单。 这是放在我的 salt master 上的 highstate/init.sls 中的。

我在这里看不到任何语法错误或间距问题。 我在这里做错了什么?

这是我的 SLS 文件

(% if pillar['highstateenabled'] == 'true' %)

enable_highstate:
  file.managed:
    - name: /etc/salt/minion.d/highstate.conf
    - source: salt://common/salt-minion/files/minion.d/highstate.conf
    - template: jinja

(% else %)

disable_highstate:
  file.absent:
    - name: /etc/salt/minion.d/highstate.conf

(% endif %)

盐调用期间的输出:

---
local:
    Data failed to compile:
----------
    Rendering SLS 'LAB:common.salt-minion' failed: mapping values are not allowed here; line 4

---

(% if pillar['highstateenabled'] == 'true' %)

enable_highstate:    <======================
  file.managed:
    - name: /etc/salt/minion.d/highstate.conf
    - source: salt://common/salt-minion/files/minion.d/highstate.conf
    - template: jinja

[...]
---

【问题讨论】:

    标签: jinja2 salt-stack


    【解决方案1】:

    最后我自己找到了解决方案:

    上面的代码使用了错误的括号。 而不是使用“()”,它应该是大括号“{}”,并且代码被正确解析。

    SLS 渲染错误并不指向这里的语法错误...

    {% if pillar['highstate'] == 'enabled' %}
    
    output:
      cmd.run:
      - name: 'echo "highstate_enabled" '
    
    enable_highstate:
      file.managed:
        - name: /etc/salt/minion.d/highstate.conf
        - source: salt://common/salt-minion/files/minion.d/highstate.conf
        - template: jinja
    
    {% else %}
    
    disable_highstate:
      file.absent:
        - name: /etc/salt/minion.d/highstate.conf
    
    {% endif %}
    

    “有时你因为树太多而看不到森林”

    【讨论】:

      猜你喜欢
      • 2014-12-13
      • 2019-10-27
      • 2019-08-16
      • 1970-01-01
      • 2016-07-13
      • 1970-01-01
      • 2019-12-09
      • 2012-02-21
      • 2015-12-14
      相关资源
      最近更新 更多