‘until’ can take a list in Ansible

George Shuklin
OpsOps
Published in
1 min readApr 14, 2021

Today I found a small, but valuable improvement for ‘until’ statement. It can be a list, and all values in the list must be truthful to have a success termination for the task.

---
- hosts: localhost
gather_facts: false
tasks:
- shell: /bin/bash -c 'echo $RANDOM'
register: res
until:
- res.stdout|int > 10000
- res.stdout|int < 20000
delay: 1
retries: 10
- debug: var=res

This playbook will print res in range of 10000–20000, or fail with timeout in unlucky event.

There are two checks: res is > 10000 AND res < 20000.

Up to the moment I would write it as much uglier statement:

until: res.stdout|int > 10000 and res.stdout|int < 20000

The key issue with ‘and’ is that it stacks really badly with multiple conditions, and if there is a need for quotes or brackets, the whole line quickly become a jinja-mess.

Using a list of conditions in this place makes code way more readable.

--

--

George Shuklin
OpsOps

I work at Servers.com, most of my stories are about Ansible, Ceph, Python, Openstack and Linux. My hobby is Rust.