problem when evaluating conditional

1,322 views
Skip to first unread message

Pablo Escobar

unread,
Feb 20, 2015, 8:14:22 AM2/20/15
to ansible...@googlegroups.com
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: 
        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.

Brian Coca

unread,
Feb 20, 2015, 8:27:53 AM2/20/15
to ansible...@googlegroups.com
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.



--
Brian Coca

Pablo Escobar

unread,
Feb 20, 2015, 8:39:15 AM2/20/15
to ansible...@googlegroups.com
Hi Brian

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

Pablo.




--
Brian Coca

--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJ5XC8kONPh%3DkStzxScP8hR6eKfhHGd8eZzCK0scUPrHkxsG_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages