2

I am trying to set value in j2 template in ansible. But the variable contains index inside it. For example:

lb_url: {{ lbip_{{index }}_url }}

But the above format doesn't work. What is the right format to support this?

franklinsijo
  • 17,784
  • 4
  • 45
  • 63

1 Answers1

1

Try lookup vars. See Other operators and the comment on + operator.

lb_url: "{{ lookup('vars', 'lbip_' ~ index ~ '_url') }}"
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63