Skip to content

capable.core219.predicate

Evaluate value with Python lambda predicate expression.

Positional and keyword arguments after O(expression), except O(on_error), are passed to the predicate after the tested value. For example 5 is capable.core219.predicate('lambda x, low, high: low <= x <= high', 1, 10) calls the predicate as predicate(5, 1, 10).

Type: raw · Required: yes

Value passed as first predicate argument.


Type: str · Required: yes

Python lambda expression string. Example lambda x: x % 2 == 0


Type: str · Default: false · Choices: false | fail

Controls behavior when predicate execution fails or does not return bool. false, given as string or boolean, returns False. fail raises plugin error. Must be passed as keyword argument; extra positional arguments are passed to the predicate.


- name: Evaluate predicate test
ansible.builtin.assert:
that:
- 4 is capable.core219.predicate('lambda x: x % 2 == 0')
- 5 is not capable.core219.predicate('lambda x: x % 2 == 0')
- name: Fail through on predicate failure
ansible.builtin.assert:
that:
- 0 is capable.core219.predicate('lambda x: 1 / x > 0', on_error='fail')

Type: bool

Predicate evaluation result.


  • Kirill Satarin (@kksat)