This is exactly what all and any tests do e.g.
- debug:
msg: "{{ [True, False] is all }}"
- debug:
msg: "{{ [True, False] is any }}"
give
msg: false
msg: true
There are no such filters in Ansible but you can write them e.g.
shell> cat filter_plugins/list2bool.py
def fall(l):
return all(l)
def fany(l):
return any(l)
class FilterModule(object):
''' Ansible filters for operating on Boolean '''
def filters(self):
return {
'fall': fall,
'fany': fany,
}
(see other plugins)
These custom filters are useful in pipes, e.g. to map lists
- debug:
msg: "{{ l|map('fall')|list }}"
vars:
l:
- [True, True]
- [True, False]
- [False, True]
- [False, False]
gives
msg:
- true
- false
- false
- false
and
- debug:
msg: "{{ l|map('fany')|list }}"
vars:
l:
- [True, True]
- [True, False]
- [False, True]
- [False, False]
gives
msg:
- true
- true
- true
- false