Bootstrap FreeKB - Ansible - Resolve "recursive loop detected in template string maximum recursion depth exceeded"
Ansible - Resolve "recursive loop detected in template string maximum recursion depth exceeded"

Updated:   |  Ansible articles

Let's say something like this is being returned.

Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ server }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ server }}'. 
Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ server }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ server }}'. 
Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ server }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ server }}'. 
Error was a <class 'ansible.errors.AnsibleError'>, original message: recursive loop detected in template string: {{ server }}. maximum recursion depth exceeded"}

 

I got this when my main playbook had the following.

---
- hosts: localhost
  vars:
    servers: ['server1', 'server2']
  tasks:
  - include_role:
      name: foo
    with_items: "{{ servers }}"
    loop_control:
      loop_var: server
...

 

And my foo role had the following.

- include_role:
    name: child2
  vars:
    server: "{{ server }}"

 

And my bar role had the following.

- debug:
    var: server

 

This basically came to trying to pass a variable named "server" from my main playbook to the foo role and then to the bar role. I resolved this by giving the variable a unique name in my foo role.

- include_role:
    name: child2
  vars:
    server_from_foo: "{{ server }}"

 

And then using the unique variable name in my bar role.

- debug:
    var: server_from_foo

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 90bf33 in the box below so that we can be sure you are a human.