Interview Prep/Ansible/Variables, Facts and Precedence

What causes "recursive loop detected in template string"?

AdvancedConceptVariables, Facts and Precedence
Answer

Variables are templated lazily, when used. A variable that refers to itself therefore loops forever.

path: "{{ path }}/bin"          # error: recursive loop detected

Fix by using a different name for the base value, or by using set_fact with a different target name so the right side is evaluated once.

base_path: /opt/app
bin_path: "{{ base_path }}/bin"

It also happens indirectly with a role default foo: "{{ foo | default('x') }}"; use a differently named variable.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence