LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-31-2020, 06:25 AM   #1
bradvan
Member
 
Registered: Mar 2009
Posts: 353

Rep: Reputation: 60
saltstack comparing jinja variables


Trying to compare two jinja variables, but not getting it correct. Get back:
Code:
Jinja syntax error: expected token ':', got '}'
The code is:
Code:
{% set CurVers = salt['pkg.version']('NessusAgent') | regex_replace('-es7', '') %}
{% set NewVers = '7.7.0' %}
{% if {{ CurVers|format(value|float) }} < {{ NewVers|format(value|float) }} %}
remove_current:
  pkg.remove:
    - name: NessusAgent
{% endif %}
CurVers is getting set to 7.4.0 and NewVers to 7.7.0. What am I doing wrong?

Last edited by bradvan; 07-31-2020 at 06:58 AM.
 
Old 07-31-2020, 09:21 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 14,875

Rep: Reputation: 4890Reputation: 4890Reputation: 4890Reputation: 4890Reputation: 4890Reputation: 4890Reputation: 4890Reputation: 4890Reputation: 4890Reputation: 4890Reputation: 4890
https://stackoverflow.com/questions/...bers-in-jinja2
I do not really understand what do you want to achieve, but instead of:
CurVers|format(value|float)
Code:
<format string>|format(CurVers|float)
whuld be better.
 
1 members found this post helpful.
Old 08-01-2020, 06:45 AM   #3
bradvan
Member
 
Registered: Mar 2009
Posts: 353

Original Poster
Rep: Reputation: 60
It turned out my problem was using '{{ }}' inside a jinja path '{% %}'. I also modified the casting:
Code:
{% set CurVers = salt['pkg.version']('NessusAgent') | regex_replace('-es7', '') |float %}
{% set NewVers = '7.7.0' %}
{% set NewVersf = NewVers | float %}
{% if CurVers < NewVersf %}
remove_current:
  pkg.remove:
    - name: NessusAgent
{% endif %}
I use NewVers later as a string. So, that is why I set it to a string first. Thanks!
 
  


Reply

Tags
saltstack


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Mastering loops with Jinja templates in Ansible LXer Syndicated Linux News 0 11-01-2019 11:12 PM
Saltstack - salt/ or pillar/, environment definition? pingu Linux - Server 1 04-08-2015 12:53 AM
comparing two variables(ipaddress) in shell scripting. suboss87 Programming 2 02-13-2013 07:07 AM
[SOLVED] Problem comparing variables Jinx-Wolf Programming 5 07-27-2011 03:27 PM
awk comparing a column value with a stored variables value bugg_deccan Programming 4 12-05-2008 07:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration