using when something > variable

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 }}”

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

Thanks, it worked.