'saltstack how to verify variable from jinja, result wrong from if statement
I was trying to write a state to set patching status, the if statement based on a result from a cmd.run, I checked the result that it should be 'No', meaning no available patches, but my state return said otherwise.
I checked:-
# salt 'minion1' cmd.run "yum --security check-update | grep 'for security'| awk '{print \$1}'"
minion1:
No
#
My state file:-
{% set minion = salt['cmd.run']("yum --security check-update | grep 'for security'| awk '{print \$1}'") %}
{% if minion|float == 'No' %}
no_patch:
cmd.run:
- name: echo "no update"
{% else %}
patch_pls:
cmd.run:
- name: echo "Patch please"
{% endif %}
my run result:-
minion1:
----------
ID: patch_pls
Function: cmd.run
Name: echo "Patch please"
Result: True
Comment: Command "echo "Patch please"" run
Started: 12:22:10.894779
Duration: 10.047 ms
Changes:
----------
pid:
19397
retcode:
0
stderr:
stdout:
Patch please
Summary for minion1
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 10.047 ms
Been spending hours trying to figure it out but just feeling defeated and frustrated right now.
You're my last hope. Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
