Short circuiting in conditionals?

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]: 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 would make it seem like things should be short circuited ?

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’)

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”}

http://docs.ansible.com/ansible/playbooks_filters.html

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