Sujeet Padhi
Sujeet Padhi

Reputation: 264

Saltstack - Unable to print output in Jinja templating

I am trying to reuse the output of a command in Saltstack, but when I try to print the output using "cmd.run", it is failing with the below error. Not sure in which format the data is getting returned from "cmd.run".

{% set output = salt['cmd.shell']('ifconfig') %}

display:
  cmd.run:
    - name: echo '{{ output }}'

Error:

    Data failed to compile:
----------
    Rendering SLS 'base:patching.install_patches' failed: mapping values are not allowed in this context

Upvotes: 0

Views: 857

Answers (1)

seshadri_c
seshadri_c

Reputation: 7340

The issue seems to be due to the placement of quotes. The single quotes are required around the entire command to run.

Below should work:

{% set output = salt['cmd.shell']('ifconfig') %}

display:
  cmd.run:
    - name: 'echo "{{ output }}"'

Upvotes: 1

Related Questions