BacklogZero®

Ansible in a Minute · Ansible Core ·

Use all and any to test list values

Short answer

Use the all test when every list value must be true. Use the any test when at least one value must be true.

Subscribe for updates

Get an email whenever we publish new guides and blog posts. Unsubscribe anytime.

By subscribing you agree we may email you about Ansible in a Minute and related Level Up Labs updates. We store your address in the same lead sheet as our contact form.

Request

print when mylist is all and when myotherlist is any

Example

A quick heads-up: Every environment is different. Review and test this example before you run it on systems you care about.

YAML
---
- hosts: all
  gather_facts: false
  vars:
    mylist: [1, "{{ 3 == 3 }}", true]
    myotherlist: [false, true]
  tasks:
    - name: Check if all elements in mylist are true
      ansible.builtin.debug:
        msg: "All elements in mylist are true"
      when: mylist is all

    - name: Check if any element in myotherlist is true
      ansible.builtin.debug:
        msg: "At least one element in myotherlist is true"
      when: myotherlist is any

How it works

all is true when every element in the list is true. any is true when at least one element is true. Put the test in when without curly braces.

When to use it

  • Gating a task on a list of checks that must all pass
  • Running a task when any flag in a list is true

Requirements

  • Ansible: >=2.14

Validation

  • Syntax validated
  • Not execution-tested
  • Last verified 2026-09-18

Notes

Added in Ansible 2.4. These are Jinja tests (is all, is any), not filters. An empty list is not all-true.

Reference

Built for every Ansible use case in every organization

BacklogZero can generate this kind of automation in your environment, just like it did here.

Get BacklogZero today

Related guides

Back to Ansible in a Minute

Use all and any to test list values · Level Up Labs