I am creating a recipe for SaltStack that installs New Relic Infrastructure monitoring on a minion. I'm trying to use the "cmd.run" option in conjunction with variables in my pillar file.
When I attempt to deploy, I get this error: failed: mapping values are not allowed here; line 3. The recipe I'm working with is here:
create-newrelic-config:
cmd.run:
- name: echo "license_key: {{pillar.newrelic.license_key}}" | sudo tee -a /etc/newrelic-infra.yml
- user: root
- group: root
This 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: ---
I'm wondering if I'm using the wrong syntax for the cmd.run function?
For reference -- though I don't think it's applicable here -- these are the install instructions I'm trying to replicate: https://docs.newrelic.com/docs/infrastructure/new-relic-infrastructure/installation/install-infrastructure-linux
Generally you can achieve many tasks with cmd.run - but in fact salt often provides a state that fits much better.
In this case you might want to use file.managed
:
/etc/newrelic.yml:
file.managed:
- user: root
- group: root
- mode: 644 # pick a mask that fits your setup.
- contents_pillar: newrelic:license_key
newrelic:
license_key: |
license_key: 1234567890abcdefghijklmnopqrstuvwxyz1234
This approach uses the contents_pillar
to specify the file content. In your pillar file the license_key
appears twice - first as the pillar key to refer to it from the state and second as the file contents for newrelic. This might be a little confusing.