I would like to achieve something like this with ansible
- debug:
msg: "{{ item }}"
with_items:
- "0"
- "1"
But to be generated from a range(2) instead of having hardcoded the iterations. How would yo do that?
- debug:
var: item
with_sequence: 0-1
or
with_sequence: start=0 end=1
or
with_sequence: start=0 count=2
Pay attention that sequences are string values, not integers (you can cast with item|int
)
Reference: Looping over Integer Sequences
Because with_sequence
is replaced by loop
and the range
function you can also use loop with range function like this example:
- hosts: localhost
tasks:
- name: loop with range functions
ansible.builtin.debug:
msg: "{{ 'number: %s' | format(item) }}"
loop: "{{ range(0, 2, 1)|list }}"