# Short circuiting in conditionals?

**URL:** <https://forum.ansible.com/t/short-circuiting-in-conditionals/19719>\
**Category:** Ansible Developer\
**Tags:** ubuntu\
**Created:** [November 10, 2015, 5:40am UTC](https://forum.ansible.com/t/short-circuiting-in-conditionals/19719 "2015-11-10T05:40:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_Tanner](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Bob\_Tanner](https://forum.ansible.com/u/Bob_Tanner)\
**Post date:** [November 10, 2015, 5:40am UTC](https://forum.ansible.com/t/short-circuiting-in-conditionals/19719/1 "2015-11-10T05:40:46Z")

</div>

Simple task.

- name: Rotate log as this user and group (14.04 or newer)  
lineinfile: \>  
dest=“/etc/logrotate.conf”  
regexp=“^su root syslog”  
insertbefore=“BOF”  
line=“su root syslog\n”  
state=“present”  
when: “‘{{ ansible\_distribution }}’ == ‘Ubuntu’ and ‘{{ ansible\_lsb.release }}’|float \>= 14.04”  
tags: logrotate

Works great until I brought my OpenIndiana systems into Ansible.

I thought the “when:” would be short circuited and the ansible\_lsb.release would never be looked at if the ansible\_distribution failed.

On OpenIndiana I get:

TASK [logrotate : Rotate log as this user and group (14.04 or newer)] \*\*\*\*\*\*\*\*\*\*  
fatal: [[crashplan.int.linvill.com](http://crashplan.int.linvill.com)]: FAILED! =\> {“failed”: true, “msg”: “ERROR! The conditional check ‘’{{ ansible\_distribution }}’ == ‘Ubuntu’ and ‘{{ ansible\_lsb.release }}’|float \>= 14.04’ failed. The error was: ERROR! ‘ansible\_lsb’ is undefined”}

[https://groups.google.com/forum/#!topic/ansible-project/MR0ZxncUCJA](https://groups.google.com/forum/#!topic/ansible-project/MR0ZxncUCJA) would make it seem like things should be short circuited ?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [November 10, 2015, 12:35pm UTC](https://forum.ansible.com/t/short-circuiting-in-conditionals/19719/2 "2015-11-10T12:35:00Z")

</div>

The problem is that you are using {{ }} to wrap variables in the when statement. So instead of just being able to evaluate vars, it’s instead templating out the when statement before evaluating it.

I’d use:

when: ansible\_distribution == ‘Ubuntu’ and ansible\_lsb.release|version\_compare(‘14.04’, ‘gte’)

---

<div class="post-metadata">

**Author:** ![Bob\_Tanner](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Bob\_Tanner](https://forum.ansible.com/u/Bob_Tanner)\
**Post date:** [November 13, 2015, 11:09pm UTC](https://forum.ansible.com/t/short-circuiting-in-conditionals/19719/3 "2015-11-13T23:09:06Z")

</div>

Deploying this ansible throws an error:

FAILED! =\> {“failed”: true, “msg”: “ERROR! The conditional check ‘ansible\_distribution == ‘Ubuntu’ and ansible\_lsb.release|version\_compare(‘14.04’, ‘gte’)’ failed. The error was: ERROR! Invalid operator type”}

---

<div class="post-metadata">

**Author:** ![Bob\_Tanner](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Bob\_Tanner](https://forum.ansible.com/u/Bob_Tanner)\
**Post date:** [November 13, 2015, 11:10pm UTC](https://forum.ansible.com/t/short-circuiting-in-conditionals/19719/4 "2015-11-13T23:10:53Z")

</div>

[http://docs.ansible.com/ansible/playbooks\_filters.html](http://docs.ansible.com/ansible/playbooks_filters.html)

```auto
<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne

```

```auto

```

```auto

```
