* Warn on tests used as filters
* Update docs, add aliases for tests that fit more gramatically with test syntax
* Fix rst formatting
* Add successful filter, alias of success
* Remove renamed_deprecation, it was overkill
* Make directory alias for is_dir
* Update tests to use proper jinja test syntax
* Update additional documentation, living outside of YAML files, to reflect proper jinja test syntax
* Add conversion script, porting guide updates, and changelog updates
* Update newly added uses of tests as filters
* No underscore variable
* Convert recent tests as filter changes to win_stat
* Fix some changes related to rebasing a few integration tests
* Make tests_as_filters_warning explicitly accept the name of the test, instead of inferring the name
* Add test for tests_as_filters_warning
* Update tests as filters in newly added/modified tests
* Address recent changes to several integration tests
* Address recent changes in cs_vpc
Tests in Jinja2 are a way of evaluating template expressions and returning True or False.
`Tests <http://jinja.pocoo.org/docs/dev/templates/#tests>`_ in Jinja are a way of evaluating template expressions and returning True or False.
Jinja2 ships with many of these. See `builtin tests`_ in the official Jinja2 template documentation.
Jinja ships with many of these. See `builtin tests`_ in the official Jinja template documentation.
Tests are very similar to filters and are used mostly the same way, but they can also be used in list processing filters, like C(map()) and C(select()) to choose items in the list.
The main difference between tests and filters are that Jinja tests are used for comparisons, whereas filters are used for data manipulation, and have different applications in jinja. Tests can also be used in list processing filters, like C(map()) and C(select()) to choose items in the list.
Like all templating, tests always execute on the Ansible controller, **not** on the target of a task, as they test local data.
Like all templating, tests always execute on the Ansible controller, **not** on the target of a task, as they test local data.
In addition to those Jinja2 tests, Ansible supplies a few more and users can easily create their own.
In addition to those Jinja2 tests, Ansible supplies a few more and users can easily create their own.
.._test_syntax:
Test syntax
```````````
`Test syntax <http://jinja.pocoo.org/docs/dev/templates/#tests>`_ varies from `filter syntax <http://jinja.pocoo.org/docs/dev/templates/#filters>`_ (``variable | filter``). Historically Ansible has registered tests as both jinja tests and jinja filters, allowing for them to be referenced using filter syntax.
As of Ansible 2.5, using a jinja test as a filter will generate a warning.
The syntax for using a jinja test is as follows::
variable is test_name
Such as::
result is failed
.._testing_strings:
.._testing_strings:
Testing strings
Testing strings
@ -24,13 +42,13 @@ To match strings against a substring or a regex, use the "match" or "search" fil
Using Ansible provided jinja tests as filters will be removed in Ansible 2.9.
Prior to Ansible 2.5, jinja tests included within Ansible were most often used as filters. The large difference in use is that filters are referenced as ``variable | filter_name`` where as jinja tests are refereced as ``variable is test_name``.
Jinja tests are used for comparisons, whereas filters are used for data manipulation, and have different applications in jinja. This change is to help differentiate the concepts for a better understanding of jinja, and where each can be appropriately used.
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:
..code-block:: yaml
when:
- result | failed
- not result | success
**NEW** In Ansible 2.5 it should be changed to look like this:
..code-block:: yaml
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, that make more sense grammatically with the jinja test syntax such as the new ``successful`` test which aliases ``success``
..code-block:: yaml
when: result is successful
See :ref:`The Ansible Tests Documentation <playbooks_tests>` for more information.
Additionally, a script was created to assist in the conversion for tests using filter syntax to proper jinja test syntax. This script has been used to convert all of the Ansible integration tests to the correct format. There are a few limitations documented, and all changes made by this script should be evaluated for correctness before executing the modified playbooks. The script can be found at `https://github.com/ansible/ansible/blob/devel/hacking/fix_test_syntax.py <https://github.com/ansible/ansible/blob/devel/hacking/fix_test_syntax.py>`_.
Modules
Modules
=======
=======
@ -41,7 +76,7 @@ The following modules no longer exist:
Deprecation notices
Deprecation notices
-------------------
-------------------
The following modules will be removed in Ansible 2.8. Please update update your playbooks accordingly.
The following modules will be removed in Ansible 2.9. Please update update your playbooks accordingly.
@ -62,6 +62,11 @@ The module formatter is a script used to generate manpages and online
module documentation. This is used by the system makefiles and rarely
module documentation. This is used by the system makefiles and rarely
needs to be run directly.
needs to be run directly.
fix_test_syntax.py
------------------
A script to assist in the conversion for tests using filter syntax to proper jinja test syntax. This script has been used to convert all of the Ansible integration tests to the correct format for the 2.5 release. There are a few limitations documented, and all changes made by this script should be evaluated for correctness before executing the modified playbooks.
Authors
Authors
-------
-------
'authors' is a simple script that generates a list of everyone who has
'authors' is a simple script that generates a list of everyone who has