Saltstack + New Relic: cmd.run returns "failed: mapping values are not allowed here;" 错误

Saltstack + New Relic: cmd.run returns "failed: mapping values are not allowed here;" error

我正在为 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

这个returns:

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

通常,您可以使用 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来指定文件内容。在你的 pillar 文件中 license_key 出现了两次 - 第一次作为从状态引用它的 pillar 键,第二次作为 newrelic 的文件内容。这可能有点令人困惑。