Skip to content

capable.core219.predicate

Build callable predicate function from Python lambda expression.

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 for that predicate call. fail raises plugin error.


- name: Build callable predicate from expression
vars:
is_even: "{{ 'lambda x: x % 2 == 0' | capable.core219.predicate }}"
ansible.builtin.assert:
that:
- is_even(4) is sameas true
- is_even(5) is sameas false
- name: Return false on predicate failure by default
vars:
nonzero: "{{ 'lambda x: 1 / x > 0' | capable.core219.predicate }}"
ansible.builtin.assert:
that:
- nonzero(0) is sameas false

Type: raw

Callable predicate function object.


  • Kirill Satarin (@kksat)