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.
More on Variables, Facts and Precedence
Where can you define variables in Ansible?BeginnerHow do you reference a variable, and when must you quote it?BeginnerGive a summary of variable precedence.IntermediateWhat are the lowest and highest precedence sources, and why does that matter?IntermediateWhat is the difference between a role's `defaults/` and `vars/`?IntermediateWhat are facts and how are they gathered?Beginner