with_nested with range()

Hi,

I need to create a nested loop referencing a variable from the outer loop. Basically something along the lines of:

hosts = [{‘name’: ‘first’, ‘limit’: 3}, {‘name’: ‘second’, ‘limit’: 5}]
for host in hosts:
for i in range(1, host[‘limit’] + 1):
print(‘%s-%d’ % (host[‘name’], i))

For all I see it’s not quite possible using with_nested or with_subelements (how do I refer to the item coming from the first loop?). I cannot enumerate all the items, they are simple int values, but their numer may be quite large.

Is there something to the built-in loops I am missing which could possibly help me using range() with limit coming from a dictionary from the first loop/data set?

Thanks in advance for any tips.

Check out loop_control
https://docs.ansible.com/ansible/playbooks_loops.html#loop-control

hosts.yml

Thank you! It gets the job done nicely indeed.

Best regards,