problem when evaluating conditional

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
    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.

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.

Hi Brian

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

Pablo.