Reputation: 105
I am writing a playbook that only should run when a new package version of a software is available. Both version numbers are custom facts I set with "set_fact"
Ansible let's you compare version numbers, so I tried it like this:
- name: compare versions
debug:
msg: "The version {{ new_version }} is newer than the old version {{ old_version }}"
when: "{{ new_version is version('{{ old_version }}', '>', strict=True }}"
Ansible throws an error that the version number is invalid. When I set "old_version" to a fixed version number it works as expected. Is it possible to compare two facts with "version"? I already tried different approaches with double-quotes etc which leads to syntax errors in ansible.
Any ideas?
Thanks
Upvotes: 3
Views: 2950
Reputation: 7340
It could be use of Jinja delimiters {{
in a conditional. In a when:
condition you don't need these delimiters to interpolate.
Example below works:
vars:
new_version: 14
old_version: 12
tasks:
- debug:
msg: 'The version {{ new_version }} is newer than the old version {{ old_version }}'
when: "new_version is version(old_version, '>')"
Upvotes: 5