# problem when evaluating conditional

**URL:** <https://forum.ansible.com/t/problem-when-evaluating-conditional/17574>\
**Category:** Ansible Project\
**Created:** [February 20, 2015, 1:13pm UTC](https://forum.ansible.com/t/problem-when-evaluating-conditional/17574 "2015-02-20T13:13:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pablo\_Escobar](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Pablo\_Escobar](https://forum.ansible.com/u/Pablo_Escobar)\
**Post date:** [February 20, 2015, 1:13pm UTC](https://forum.ansible.com/t/problem-when-evaluating-conditional/17574/1 "2015-02-20T13:13:55Z")

</div>

Hi all,

I have tried to execute these tasks inside a bigger playbook:

- name: Check if piwik folder already exists  
stat: path={{ item.documentroot }}/piwik/index.php  
with\_items:  
apache\_vhosts  
register: piwik\_files  
tags: test

- name: Download piwik  
get\_url:  
url=[http://builds.piwik.org/piwik.zip](http://builds.piwik.org/piwik.zip)  
dest={{ item.documentroot }}  
with\_items:  
apache\_vhosts  
when: piwik\_files.stat.exists == false  
tags: test

but I was always getting the error: “error while evaluating conditional: piwik\_files.stat.exists == false”

Using the ansible debug option to check the content of “piwik\_files” variable I found that I could workaround the error when I change my conditional to this:

when: piwik\_files.results[0].stat.exists == false

In other simpler playbooks I never found this problem with conditional and I don’t know why I am getting this issue in this one. Usually variableName.stat.exists works without the need of doing variableName.results[0].stat.exists

Any suggestion about why this could be happening or what am I doing wrong? I am using ansible 1.7.2 in a centos7 machine with python2.7.5. I also tried to use ansible 1.8.3 in a python virtualenv but I still get the same error.

thanks in advance for your help  
Pablo.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 20, 2015, 1:27pm UTC](https://forum.ansible.com/t/problem-when-evaluating-conditional/17574/2 "2015-02-20T13:27:48Z")

</div>

any task that uses with\_ will put the results in a list, hence the  
extra [0] you need, which is actually chekcing that the first item in  
list returns this, not the whole list.

---

<div class="post-metadata">

**Author:** ![Pablo\_Escobar](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Pablo\_Escobar](https://forum.ansible.com/u/Pablo_Escobar)\
**Post date:** [February 20, 2015, 1:38pm UTC](https://forum.ansible.com/t/problem-when-evaluating-conditional/17574/3 "2015-02-20T13:38:41Z")

</div>

Hi Brian

thanks for your quick reply. Now I understand, thanks for the clarification.

Pablo.
