using when something > variable

20 views
Skip to first unread message

Spiro Mitsialis

unread,
Mar 4, 2019, 1:39:34 PM3/4/19
to Ansible Project
I have a playbook that performs a command on a router and then parses the output.  So far no problem.
I'm then trying to check if any of the variables back from the parser are >=   threshold.  The threshold is defined as a variable in the playbook.  No problem with it.
vars:
  threshold
: 90
  tcam_full
: False

Although I do not get any error messages the following is never true, even when it should be.  Is there a way to make it work?
   - name: check ACL Mask
     set_fact
:
       tcam_full
: true
     
when: item.acl_mask >= "{{ threshold }}"
     with_items
: "{{ tcam.tcam_resources }}"

If I add a threshold manually like below it works fine.  I have several of these statements and would rather not hard code the threshold value
   - name: check ACL Entries
     set_fact
:
       tcam_full
: true
     
when: item.acl_ent >= 90
     with_items
:  "{{ tcam.tcam_resources }}"

Finally, I also get a warning message about using jinja2 templates with a when statement.  How should I be doing it? I've had similar messages when checking if a {{ variable }} == something.

[WARNING]: when statements should not include jinja2 templating delimiters
36
such as {{ }} or {% %}. Found: item.acl_mask >= "{{ threshold }}"

Pshem Kowalczyk

unread,
Mar 4, 2019, 2:13:00 PM3/4/19
to Ansible Project
Hi,

inside 'when' all variables are automatically accessible, so you don't have to use brackets. This should work:
when: item.acl_mask >= threshold

kind regards
Pshem


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3520d313-7ad3-4770-8584-0255f5ecc59d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Spiro Mitsialis

unread,
Mar 4, 2019, 3:14:58 PM3/4/19
to Ansible Project
Thanks, it worked.

Reply all
Reply to author
Forward
0 new messages