【问题标题】:Saltstack + New Relic: cmd.run returns "failed: mapping values are not allowed here;" errorSaltstack + New Relic:cmd.run 返回“失败:此处不允许映射值;”错误
【发布时间】:2017-02-25 03:50:23
【问题描述】:

我正在为 SaltStack 创建一个配方,用于在一个 minion 上安装 New Relic Infrastructure 监控。我正在尝试将“cmd.run”选项与我的支柱文件中的变量一起使用。

当我尝试部署时,我收到此错误:失败:此处不允许映射值;第 3 行。我正在使用的配方在这里:

create-newrelic-config:
    cmd.run:
        - name: echo "license_key: {{pillar.newrelic.license_key}}" | sudo tee -a /etc/newrelic-infra.yml
        - user: root
        - group: root

这会返回:

out: project-django-support-01:
out:     Data failed to compile:
out: ----------
out:     Rendering SLS 'base:packages.newrelic' failed: mapping values are not allowed here; line 3
out: 
out: ---
out: create-newrelic-config:
out:     cmd.run:
out:         - name: echo "license_key: 000000000000000000000000000" | sudo tee -a /etc/newrelic-infra.yml    <======================
out:         - user: root
out:         - group: root
out: 
out: enable-newrelic-gpg:
out:     cmd.run:
out: [...]
out: ---

我想知道我是否对 cmd.run 函数使用了错误的语法?

仅供参考——尽管我认为它不适用于这里——这些是我试图复制的安装说明:https://docs.newrelic.com/docs/infrastructure/new-relic-infrastructure/installation/install-infrastructure-linux

【问题讨论】:

    标签: newrelic salt-stack


    【解决方案1】:

    通常您可以使用 cmd.run 完成许多任务 - 但实际上 salt 通常会提供更适合的 state

    在这种情况下,您可能想使用file.managed

    state.sls

    /etc/newrelic.yml:
      file.managed:
        - user: root
        - group: root
        - mode: 644  # pick a mask that fits your setup.
        - contents_pillar: newrelic:license_key
    

    pillar.sls

    newrelic:
      license_key: |
          license_key: 1234567890abcdefghijklmnopqrstuvwxyz1234
    

    这种方法使用contents_pillar 来指定文件内容。在您的支柱文件中,license_key 出现两次 - 第一次作为支柱键从状态中引用它,第二次作为 newrelic 的文件内容。这可能有点令人困惑。

    【讨论】:

    • 这更有意义!谢谢!
    猜你喜欢
    • 2016-07-13
    • 2015-12-14
    • 1970-01-01
    • 2014-12-13
    • 2019-10-27
    • 2019-08-16
    • 2020-01-17
    • 2021-03-15
    • 1970-01-01
    相关资源
    最近更新 更多