Updated ansible failed on checks

Hi all,

After running ansible 2.9, I’m getting these errors:

fatal: [jjohnson-lx]: FAILED! => {“msg”: “The conditional check ‘ansible_distribution_major_version | version_compare(‘6’, ‘=’)’ failed. The error was: template error while templating string: no filter named ‘version_compare’. String: {% if ansible_distribution_major_version | version_compare(‘6’, ‘=’) %} True {% else %} False {% endif %}\n\nThe error appears to be in ‘/zabbix.yml’: line 76, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: "install 6 if not exists (no proxy)"\n ^ here\n”}

The syntax you are using was deprecated in Ansible 2.5 and should have been emitting a deprecation warning. See this doc for more info:

https://docs.ansible.com/ansible/latest/porting_guides/porting_guide_2.5.html#jinja-tests-used-as-filters

Effectively you need to change the | to is

In addition to changing the deprecated syntax use "version" instead of
"version_compare"
https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#version-comparison

(Just curious). It's not clear why 2.9 complains "no filter named
'version_compare'". Both names of the filter are present in 2.9 source
https://github.com/ansible/ansible/blob/stable-2.9/lib/ansible/plugins/test/core.py

            # version comparison
            'version_compare': version_compare,
            'version': version_compare,

(lines 199-201)

, and I can't find any explanation in the "porting guides" and "release notes"
either.
https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html
https://docs.ansible.com/ansible/latest/porting_guides/

What am I missing ?

Thank you,

  -vlado

Vlado,

You're not missing anything. The version_compare test still exists, is not deprecated, and is fine to use — just not as a filter.

We used to register tests as filters. Since we no longer do this, Jinja raises an error that version_compare is not a valid filter, which is accurate.

Sam,

thank you very much for the clarification!

For the record, quoting from *Ansible 2.9 "Immigrant Song" Release Notes*
https://github.com/ansible/ansible/blob/stable-2.9/changelogs/CHANGELOG-v2.9.rst#id2

  * Jinja tests - Remove deprecated functionality of registering tests as
    filters (https://github.com/ansible/ansible/issues/55319)

(This explains the error in 2.9: "no filter named 'version_compare'")

  -vlado

Thanks all!