ansible jinja2 – how to use "loop range" output in other "for statement"

I want to use the n values in the next for statement and I expect output as router_0, router_1. But any optisons like router_[n], router_{{ n }}, router_(n) etc didnt work. How can we do this?

{% for n in range(0, 2) %}
 {% for rtr in web.router_[n] %}
  {% if rtr.interface.type == 'lacp' %}
  interface Port-Channel{{ rtr.interface.id }}
 .
  {% endif %}
 {% endfor %}
{% endfor %}

In vars.yaml, there are variables for paired routers, router_0 and router_1. I want to generate the config template for both routers at the same time.

Thanks,



Read more here: https://stackoverflow.com/questions/64948889/ansible-jinja2-how-to-use-loop-range-output-in-other-for-statement

Content Attribution

This content was originally published by frd at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: