Why Jinja Tests Used As Search Filters Not Working After Upgrading Ansible Engine to 2.9 ?

Solution Verified - Updated -

Environment

  • Ansible Engine 2.9

Issue

When using jinja tests as filters Ansible playbooks fail with a error as filters was depreciated in Ansible 2.5 and then removed in Ansible 2.9 .

Resolution

As of Ansible 2.5, using an Ansible provided jinja test with filter syntax, will display a deprecation error.

OLD In Ansible 2.4 (and earlier) the use of an Ansible included jinja test would likely look like this:

when:
    - result | failed
    - not result | success

NEW In Ansible 2.5 it should be changed to look like this:

when:
    - result is failed
    - results is not successful

In addition to the deprecation warnings, many new tests have been introduced that are aliases of the old tests. These new tests make more sense grammatically with the jinja test syntax, such as the new successful test which aliases success.

when: result is successful

Root Cause

Using Jinja tests as filters was depreciated in Ansible 2.5 and then removed in Ansible 2.9 which is why you are seeing this error after the upgrade.

Please check the following 2.5 porting guide for more information here

Diagnostic Steps

Issue on search filter upgrading Ansible Engine to 2.9:

fatal: [xxxxx]: FAILED! => {"msg": "The conditional check 'ansible_default_ipv4.address | search("10.73")' failed. The error was: template error while templating string: no filter named 'search'

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments