That won't quite work as you cannot access the whole list this way. However:
http://docs.ansible.com/playbooks_loops.html#id20 each item and it's successor: - debug: msg="at index {{ item[0] }} there lies a value {{ item[1] }} and the next item is {{ foo[item[0]] }}" with_indexed: foo Though you'll walk off the end of the list and will need to account for that. It seems it would be much better to instead loop over a hash. my_setup: - partition: foo mount: bar - partition: baz mount: quux with_items: my_setup {{ item.mount }} and {{ item.partition }} etc. On Mon, Feb 3, 2014 at 2:37 PM, Kahlil Hodgson < [email protected]> wrote: > Try {{ item|int +1 }} > > K > On 04/02/2014 5:58 AM, <[email protected]> wrote: > >> Hello, >> >> In certain cases it's useful to be able to add a number to the value of >> an {{ item }} variable >> >> For example when creating md (raid) devices, md0 for example is made up >> of partitions sda1 and sdb1. >> >> with_items: >> [ 0, 1, 2, 3, 4 etc ] >> >> It would be nice to be able to reference {{ item }} for the md device >> names as well >> as {{ item + 1 }} for the partition names. >> >> {{ item + 1 }} didn't seem to work for me and I haven't been able to find >> anything online or >> in the documentation as to whether something like this is possible. >> >> I wound up using with_together with two sequences for ex. [0, 1, 2 ] and >> [1, 2, 3] but it's >> not completely elegant and can lead to typing errors. >> >> Any hints? >> >> Thanks in advance, >> --Ed >> >> -- >> 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]. >> For more options, visit https://groups.google.com/groups/opt_out. >> > -- > 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]. > For more options, visit https://groups.google.com/groups/opt_out. > -- Michael DeHaan <[email protected] <[email protected]>> CTO, Ansible, Inc. http://www.ansible.com/ <http://www.ansibleworks.com/> -- 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]. For more options, visit https://groups.google.com/groups/opt_out.
