I just added debug to the variable:

<!-- FCC:      {{ foundQueuesCount }}
 {{ foundQueuesCount | type_debug }} -->


and got this:

<!-- FCC:      0

 AnsibleUnsafeText -->

<!-- inside queue greater than 1 -->


Are all variables passed to by Ansible to Jinja as text?  If so, I guess I 
need to cast them to their proper type within the Jinja template?



On Wednesday, July 24, 2019 at 9:40:54 AM UTC-4, Adam wrote:
>
> Hi Dick - 
>
> Isn't that done with |int?  like this:
>
> foundQueuesCount: "{{lookup('file', 
> '{{appdataRoot}}/tempqueues_{{item.router_name}}.txt')|length|int }}"
>
>
> Is there another way?
>
>
>
>
> On Wednesday, July 24, 2019 at 9:25:39 AM UTC-4, Dick Visser wrote:
>>
>> Try casting it explicitly to int?
>>
>> On Wed, 24 Jul 2019 at 15:14, Adam <a.m...@gmail.com> wrote:
>>
>>> 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!
>>>
>>> -- 
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/ansible-project/1b07c9ef-f90f-4511-be21-a808640f7c12%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/ansible-project/1b07c9ef-f90f-4511-be21-a808640f7c12%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> -- 
>> Dick Visser
>> Trust & Identity Service Operations Manager
>> GÉANT
>>
>

-- 
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4d489d0f-517e-4a25-84f9-643ef6747f85%40googlegroups.com.

Reply via email to