Bharath Thiruveedula
Bharath Thiruveedula

Reputation: 401

How to use variable inside variable in ansible jinja template

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?

Upvotes: 2

Views: 1641

Answers (1)

Vladimir Botka
Vladimir Botka

Reputation: 67959

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

lb_url: "{{ lookup('vars', 'lbip_' ~ index ~ '_url') }}"

Upvotes: 1

Related Questions