Hi -
I’m trying to evaluate the length of “foundQueuesCount” below in a Jinja template and use a conditional. Everything works perfectly except for when the length is zero.
The task:
- name: build routerconfig
template:
src: templates/{{item.version}}/routerconfig.j2
dest: "{{smq_path}}/config/{{item.router_name}}/routerconfig.xml"
owner: appuser
group: appuser
mode: 0744
with_items: "{{routers}}"
vars:
foundQueues: "{{lookup('file', '{{appdataRoot}}/tempqueues_{{item.router_name}}.txt', wantlist=True) }}"
foundQueuesCount: "{{lookup('file', '{{appdataRoot}}/tempqueues_{{item.router_name}}.txt')|length|int }}"
when: item.hostname == ansible_hostname
From the template:
FCC: {{ foundQueuesCount }}
{% if foundQueuesCount > 1 %}
<!-- inside queue greater than 1 -->
{% else %}
<!-- inside else condition -->
{% endif %}
It finds the count correctly when the temp file has records & goes into the correct part of the 'if' condition:
FCC: 14624
<!-- inside queue greater than 1 -->
But, if the count is 0, it doesn't fall into the 'else' condition.
FCC: 0
<!-- inside queue greater than 1 -->
This is really simple. What in the world am I overlooking?
Thanks!