Thank you! It gets the job done nicely indeed.
Best regards, 2016-12-19 15:20 GMT+01:00 Kai Stian Olstad <[email protected] >: > On 19. des. 2016 14:47, Łukasz Górski wrote: > >> 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? >> > > Check out loop_control > https://docs.ansible.com/ansible/playbooks_loops.html#loop-control > > hosts.yml > --- > - debug: msg="{{ outer_item.name }}-{{ item }}" > with_sequence: start=1 end={{ outer_item.limit }} > > playbook.yml > - hosts: localhost > vars: > hosts: > - name: 'first' > limit: 3 > - name: 'second' > limit: 5 > > tasks: > - include: hosts.yml > with_items: "{{ hosts }}" > loop_control: > loop_var: outer_item > > -- > Kai Stian Olstad > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ms > gid/ansible-project/4ef65fab-a801-3c9f-e55e-b69952990a2f%40olstad.com. > For more options, visit https://groups.google.com/d/optout. > -- *Łukasz Górski* Administrator Systemu Linux e-mail: [email protected] Tel. 058 321 95 65 Kom. <http://trojmiasto.pl> Moje miasto to Trójmiasto! ------------------------------ Trojmiasto.pl Sp. z o.o. ul. Wały Piastowskie 1, 80-855 Gdańsk tel: 58 321-95-00 fax: 58 321-95-13 e-mail: [email protected] NIP 583-30-12-490, REGON 220563678 Sąd Rejonowy Gdańsk-Północ w Gdańsku, VII Wydział Gospodarczy Krajowego Rejestru Sądowego, KRS 0000300002, Kapitał zakładowy 2 150 000 PLN [image: fb] <http://www.facebook.com/trojmiastopl> Trojmiasto.pl na Facebooku. Dołącz do nas! <http://www.facebook.com/trojmiastopl> -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEpJg8kpXdrnL20b-EPFcW8VtLAoPNhDA8C9upRB2%2BVAb6qM%2BA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
