Loop range format quick question

14 views
Skip to first unread message

Dave Zarei

unread,
May 5, 2020, 8:36:28 AM5/5/20
to Ansible Project
HI,

quick question about how to use a variable in loop range:

I got this:

loop: "{{range (0, 2+1) | list}}"


and this is what i want to use:

loop: "{{range (0, myvariable +1) | list}}"


where "myvaribale" contains  number 2


but it comes back with an error when i run it, i also tried to put myvariable in double quote, single quote, but no help, is there any specific format to put myvariable in here?

Thanks,
Dave.

Stefan Hornburg (Racke)

unread,
May 5, 2020, 8:53:49 AM5/5/20
to ansible...@googlegroups.com
You might need to use myvariable | int as Jinja results are strings - but it is always helpful to post the error with
your question.

Regards
Racke

>
> Thanks,
> Dave.
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/878dd0d2-d4f3-4196-b7ab-bb2a8ed5dd9f%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/878dd0d2-d4f3-4196-b7ab-bb2a8ed5dd9f%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Dave Zarei

unread,
May 8, 2020, 12:35:17 PM5/8/20
to Ansible Project
Thanks Stefan, used the following and it's working like you said:

loop: "{{range (0, myvariable | int +1) | list}}"
Reply all
Reply to author
Forward
0 new messages