# Complex conditionnal when statement - second part is not evaluated

**URL:** <https://forum.ansible.com/t/complex-conditionnal-when-statement-second-part-is-not-evaluated/24459>\
**Category:** Ansible Project\
**Created:** [May 11, 2017, 9:50am UTC](https://forum.ansible.com/t/complex-conditionnal-when-statement-second-part-is-not-evaluated/24459 "2017-05-11T09:50:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Myssa](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@Myssa](https://forum.ansible.com/u/Myssa)\
**Post date:** [May 11, 2017, 9:50am UTC](https://forum.ansible.com/t/complex-conditionnal-when-statement-second-part-is-not-evaluated/24459/1 "2017-05-11T09:50:09Z")

</div>

Hello everyone !

I’ve got a small problem when trying to evaluate this task :

- name: Testing port 80 - 443 - 8443 on server\_x  
wait\_for: host=server\_x port={{item}} timeout=1  
with\_items:
- 80
- 443
- 8443  
when: (sg\_building == “TIGERY” and sg\_marley\_environment == “DEV” and sg\_building is defined and sg\_marley\_environment is defined) or (specified\_building == “TIGERY” and specified\_environment == “DEV” and specified\_building is defined and specified\_environment is defined)

sg\_building and sg\_marley\_environement are populated from the dynamic inventory.  
specified building and specified\_environement are passed to the playbook via extra-vars (-e option with the ansible-playbook command)

It looks like only the first part of the condition (before the “or”) is evaluated : do you have any idea why ? (it’s skipping if the condition is after the “or”)

Thank you for help !

Regards,  
Samy Girard
