Skip to content

capable.core219.predicate

Return callable predicate function from Python lambda expression.

Required: yes

One term is required. 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: Return predicate function and use in playbook
vars:
is_even: "{{ lookup('capable.core219.predicate', 'lambda x: x % 2 == 0') }}"
ansible.builtin.assert:
that:
- is_even(4) is sameas true
- is_even(5) is sameas false
- name: Fail through on predicate failure
vars:
will_fail: "{{ lookup('capable.core219.predicate', 'lambda x: 1 / x > 0', on_error='fail') }}"
ansible.builtin.debug:
msg: "{{ will_fail(0) }}"

Type: raw

Callable predicate function object.


  • Kirill Satarin (@kksat)