ansible/ansible — pull request #6584 by sivel (2014-03-19 16:31:52+00:00)
Title: Expose ansible_version to playbooks, add version_compare filter. #fixes 6583

A number of people have asked for the ansible version to be exposed to playbooks.

This pull request exposes it as `ansible_version`.

Additionally, on it's own, it is complicated to compare that version to another value.

This pull request additionally adds a `version_compare` filter for easy comparison of versions.

Unit tests have been added for the new filter, and here is an example playbook to see this in action:

```
---
- hosts: all
tasks:
- debug:
var: ansible_version

- debug:
msg: "{{ ansible_version|version_compare(1.6) }}"

- debug:
msg: "{{ ansible_version|version_compare(1.4, 'gt') }}"

- debug:
msg: "{{ ansible_version|version_compare(1.7, 'lt') }}"

- debug:
msg: "{{ ansible_version|version_compare(1.6, '>=') }}"

- debug:
msg: "{{ ansible_version|version_compare(1.6, '<') }}"
```

The `version_compare` accepts an 'operator' argument, which supports: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne