1

I have a task like this:

- include: tasks/install_nginx_vhost.yml
  vars:
    domain_name: learn.{{ domain_name }}

- include: tasks/install_nginx_vhost.yml
  vars:
    domain_name: author.{{ domain_name }}

But I am getting this error:

recursive loop detected in template string

Is it possible to temporarily (only for the include) override a variable like this? Because I don't want to create additional variables.

warvariuc
  • 57,116
  • 41
  • 173
  • 227
  • 1
    PS: Can't help but mention that it's clearly stupidity on ansible's part of report such an error given that it only makes one pass in evaluating expressions: http://stackoverflow.com/questions/29276198/ansible-how-to-construct-a-variable-from-another-variable-and-then-fetch-its-v/29280622#29280622 – Kashyap Mar 27 '15 at 14:57

1 Answers1

2

Not really.

- set_fact:
    learn_domain_name:  "learn.{{ domain_name }}"
    author_domain_name: "author.{{ domain_name }}"

- include: tasks/install_nginx_vhost.yml
  vars:
    domain_name: "{{ learn_domain_name }}"

- include: tasks/install_nginx_vhost.yml
  vars:
    domain_name: "{{ author_domain_name }}"

or more advisable, if possible, would be you rename the original domain_name say to domain_name_suffix. Then:

- include: tasks/install_nginx_vhost.yml
  vars:
    domain_name: learn.{{ domain_name_suffix }}

- include: tasks/install_nginx_vhost.yml
  vars:
    domain_name: author.{{ domain_name_suffix }}
warvariuc
  • 57,116
  • 41
  • 173
  • 227
Kashyap
  • 15,354
  • 13
  • 64
  • 103