Firstly, the code snippet is incorrect in how you took care of the only apostrophe. Please note that you have less.
{% set project = '/home/project_name' %}
{% if salt['cmd.run']('ls -lt {{ project }}') | wc -l') == 2 %}
<STATE>
{% endif %}
This is the correct version as the only apostrophe goes:
{% set project = '/home/project_name' %}
{% if salt['cmd.run']('ls -lt {{ project }}) | wc -l') == 2 %}
<STATE>
{% endif %}
Second, combine the value of the variable with the ~ command, which concatenates the two lines.
Here is what I found about the ~ operator in the Jinja 2 2.7.2 documentation:
~
Converts all operands into strings and concatenates them. {{ "Hello " ~ name ~ "!" }}
would return (assuming name is 'John') Hello John!.
So here is the final correct version:
{% set project = '/home/project_name' %}
{% if salt['cmd.run']('ls -lt' ~ project ~ ') | wc -l') == 2 %}
<STATE>
{% endif %}
source
share