Failed to template {{ variable_name }}, recursive loop error

I have a playbook that runs 2 plays and then includes a playbook from another project. When calling the external playbook, it attempts to pass along a couple of variables so that the external playbook has the proper context. The playbook looks like this:

  • name: Launch any new EC2 instances
    hosts: local
    gather_facts: false
    roles:

  • { role: ec2, server_type: web, server_type_abbrev: web, when: “‘web’ in server_types” }

  • name: Configure new EC2 instances
    hosts: ec2_instances
    become: yes
    become_method: sudo
    gather_facts: true
    roles:

  • common/server-config/essentials

  • common/server-config/github

  • name: Deploy the Project
    include: “…/…/project/ansible/aws.yml target_env={{ env }} aws_region={{ aws_region }}”

If I remove the aws_region variable from the playbook include, all is well. With it in, though:

[WARNING]: non fatal error while trying to template play variables: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: Failed to template {{ aws_region }}: Failed to
template {{ aws_region }}: recursive loop detected in template string: {{
aws_region }}

What am I doing wrong here?

Thanks.

It appears to be because you are setting a variable to itself:

aws_region={{ aws_region }}

Without trying it, you may just be able to omit providing that, because the variable is already defined as you want it.

Otherwise, you will have to change the name of one of those variables.

I did try changing the variable name to “region”, e.g.

region={{ aws_region }}

but that didn’t change anything. To improve my understanding…are you telling me that even when calling an external playbook, all variables created in the initial playbook are still in scope? I didn’t really even consider that since it’s, well, external. I’ll try that first.

Thanks, Matt.