我正在创建saltstack的食谱,该食谱在小兵上安装新的遗物基础架构监视。我正在尝试将" cmd.run"选项与我的支柱文件中的变量一起使用。
当我尝试部署时,我会得到此错误:失败:此处不允许映射值;第3行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/安装/安装Infrastructure-Linux
通常,您可以使用cmd.run实现许多任务 - 但实际上,盐通常提供了一个更好的状态。
在这种情况下,您可能需要使用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的文件内容。这可能有点令人困惑。