# unable to evaluate conditional

**URL:** <https://forum.ansible.com/t/unable-to-evaluate-conditional/22427>\
**Category:** Ansible Project\
**Created:** [August 31, 2016, 9:43am UTC](https://forum.ansible.com/t/unable-to-evaluate-conditional/22427 "2016-08-31T09:43:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [August 31, 2016, 9:43am UTC](https://forum.ansible.com/t/unable-to-evaluate-conditional/22427/1 "2016-08-31T09:43:51Z")

</div>

Hello,

I don’t understand where I am doing wrong in this simple tasks:

- name: Search for bin directory  
stat:  
path: /{{ Directoryname }}/{{ item }}/bin  
register: previous  
with\_items: “{{ shr4you\_inst.stdout\_lines }}”  
when: shr4you\_inst|success

- debug: msg=“previous {{previous}}”

- name: stop karaf  
shell: chdir={{ previous.stat.path }} ./stop  
async: 5  
poll: 5  
ignore\_errors: True  
when: previous.stat.isdir

The last When: condition is ALWAYS running with this error: “The error was: unable to evaluate conditional: previous.stat.isdir”

Here is the logfile:

TASK [4YOU : Search for bin directory] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [integuno] =\> (item=SHR\_4YOU-hra-1.1.0-SNAPSHOT)

TASK [4YOU : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [integuno] =\> {  
“msg”: “previous {‘msg’: u’All items completed’, ‘changed’: False, ‘results’: [{u’stat’: {u’uid’: 54322, u’exists’: True, u’woth’: False, u’mtime’: 1472557536, u’inode’: 21695026, u’isgid’: False, u’size’: 4096, u’wgrp’: False, u’isuid’: False, u’isreg’: False, u’pw\_name’: u’integuno’, u’gid’: 54323, u’ischr’: False, u’wusr’: True, u’xoth’: True, u’rusr’: True, u’nlink’: 2, u’issock’: False, u’rgrp’: True, u’gr\_name’: u’hr’, u’path’: u’/integuno/DV70\_EX/SHR\_4YOU-hra-1.1.0-SNAPSHOT/bin’, u’xusr’: True, u’atime’: 1472557622, u’isdir’: True, u’ctime’: 1472634055, u’isblk’: False, u’xgrp’: True, u’dev’: 64768, u’roth’: True, u’isfifo’: False, u’mode’: u’0755’, u’islnk’: False}, u’changed’: False, ‘\_ansible\_no\_log’: False, ‘\_ansible\_item\_result’: True, ‘item’: u’SHR\_4YOU-hra-1.1.0-SNAPSHOT’, ‘invocation’: {‘module\_name’: u’stat’, u’module\_args’: {u’checksum\_algorithm’: u’sha1’, u’mime’: False, u’get\_checksum’: True, u’follow’: False, u’path’: u’/integuno/DV70\_EX/SHR\_4YOU-hra-1.1.0-SNAPSHOT/bin’, u’get\_md5’: True}}}]}”  
}

TASK [4YOU : stop karaf] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [integuno]: FAILED! =\> {“failed”: true, “msg”: “The conditional check ‘previous.stat.isdir’ failed. The error was: unable to evaluate conditional: previous.stat.isdir\n\nThe error appears to have been in ‘/home/fvaltat/4YOU/roles/4YOU/tasks/sauvegarde.yml’: line 18, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: stop karaf\n ^ here\n”}  
…ignoring

Thanks for your help,  
Regards

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [August 31, 2016, 10:29am UTC](https://forum.ansible.com/t/unable-to-evaluate-conditional/22427/2 "2016-08-31T10:29:06Z")

</div>

if I add 2 debug tasks this way , it seems the previous.stat is not defined anymore.

- debug: msg=“previous {{previous}}”
- debug: msg=“previous isdir {{previous.stat.isdir}}”
- debug: msg=“previous path {{previous.stat.path}}”

TASK [4YOU : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [integuno] =\> {  
“msg”: “previous {‘msg’: u’All items completed’, ‘changed’: False, ‘results’: [{u’stat’: {u’uid’: 54322, u’exists’: True, u’woth’: False, u’mtime’: 1472557536, u’inode’: 21695026, u’isgid’: False, u’size’: 4096, u’wgrp’: False, u’isuid’: False, u’isreg’: False, u’pw\_name’: u’integuno’, u’gid’: 54323, u’ischr’: False, u’wusr’: True, u’xoth’: True, u’rusr’: True, u’nlink’: 2, u’issock’: False, u’rgrp’: True, u’gr\_name’: u’hr’, u’path’: u’/integuno/DV70\_EX/SHR\_4YOU-hra-1.1.0-SNAPSHOT/bin’, u’xusr’: True, u’atime’: 1472557622, u’isdir’: True, u’ctime’: 1472634055, u’isblk’: False, u’xgrp’: True, u’dev’: 64768, u’roth’: True, u’isfifo’: False, u’mode’: u’0755’, u’islnk’: False}, u’changed’: False, ‘\_ansible\_no\_log’: False, ‘\_ansible\_item\_result’: True, ‘item’: u’SHR\_4YOU-hra-1.1.0-SNAPSHOT’, ‘invocation’: {‘module\_name’: u’stat’, u’module\_args’: {u’checksum\_algorithm’: u’sha1’, u’mime’: False, u’get\_checksum’: True, u’follow’: False, u’path’: u’/integuno/DV70\_EX/SHR\_4YOU-hra-1.1.0-SNAPSHOT/bin’, u’get\_md5’: True}}}]}”  
}

TASK [4YOU : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [integuno] =\> {  
“msg”: “previous isdir {{previous.stat.isdir}}”  
}

TASK [4YOU : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [integuno] =\> {  
“msg”: “previous path {{previous.stat.path}}”

Any idea ?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 31, 2016, 10:50am UTC](https://forum.ansible.com/t/unable-to-evaluate-conditional/22427/3 "2016-08-31T10:50:27Z")

</div>

It very hard to read the output using debug this way, please use this instead  
- debug: var=previous

If you do you probably will see what's happening a lot easier.

When you use register with with\_items the result back is a list.

[https://docs.ansible.com/ansible/playbooks\_loops.html#using-register-with-a-loop](https://docs.ansible.com/ansible/playbooks_loops.html#using-register-with-a-loop)

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [August 31, 2016, 10:52am UTC](https://forum.ansible.com/t/unable-to-evaluate-conditional/22427/4 "2016-08-31T10:52:27Z")

</div>

I finally found out how to solve this but I don’t understand why.  
I had to use the following syntax to use the register variable, even if the register variable was not containing an “\_” in its name:

- debug: msg=“previous {{previous}}”
- debug: msg=“previous isdir {{previous.results[0].stat.isdir}}”
- debug: msg=“previous path {{previous.results[0].stat.path}}”

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [September 1, 2016, 8:55am UTC](https://forum.ansible.com/t/unable-to-evaluate-conditional/22427/5 "2016-09-01T08:55:26Z")

</div>

ok thank you for the explanation  
REgards
