# Did I take this concept too far or is this a bug?

**URL:** <https://forum.ansible.com/t/did-i-take-this-concept-too-far-or-is-this-a-bug/24739>\
**Category:** Ansible Project\
**Created:** [June 15, 2017, 5:42pm UTC](https://forum.ansible.com/t/did-i-take-this-concept-too-far-or-is-this-a-bug/24739 "2017-06-15T17:42:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Balduf](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Ed\_Balduf](https://forum.ansible.com/u/Ed_Balduf)\
**Post date:** [June 15, 2017, 5:42pm UTC](https://forum.ansible.com/t/did-i-take-this-concept-too-far-or-is-this-a-bug/24739/1 "2017-06-15T17:42:43Z")

</div>

I have a large playbook, which creates groups of VMs in a cloud and each VM needs some number of data volumes attached. I attempted to make it as modular as possible and started using roles and include\_roles in loops. To do this, I have a role which loops over an include\_role for the VMs and then that VM role loops over an include\_role for the Volumes. The problem is that the variable for the VM name doesn’t get passed properly through the second loop to be used in the volume creation role. Should it?

basically it looks something like this:

role1  
loop1: var1  
include: role2  
include: role3  
loop2: var2  
include: role4

The first pass through loop1 everything is fine. The second (and subsequent) passes when you print var1 in role4 you still get var1 set to what it was for the first pass. Here is all the code from a boiled down example (with output):

test.playbook

- hosts: localhost  
connection: local  
gather\_facts: false  
vars:  
variable1: default  
the\_items:
- name: item1  
roles:
- role\_1

roles/role\_1/tasks/main.yml

- name: “Role\_1\_inc\_2”  
include\_role:  
name: role\_2  
vars:  
variable1: “{{ item }}”  
with\_sequence: count=2 format=“Outer%02x”

roles/role\_2/task/main.yml

- name: “role\_2\_inc\_3”  
include\_role:  
name: role\_3

roles/role\_3/tasks/main.yml

- name: “role\_3\_inc\_4”  
include\_role:  
name: role\_4  
vars:  
r4\_name: “{{ a\_item.name }}”  
with\_items: “{{ the\_items }}”  
loop\_control:  
loop\_var: a\_item

roles/role\_4/tasks/main.yml

- debug:  
msg: “role\_4: {{ variable1 }} - {{ r4\_name }}”

output:  
PLA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\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“changed”: false,  
“msg”: “role\_4: Outer01 - item1”  
}

Notice the Outer loop variable is stuck at 01 for both loops.

ansible-playbook --version  
ansible-playbook 2.3.0.0  
config file = /etc/ansible/ansible.cfg  
configured module search path = Default w/o overrides  
python version = 2.7.13 (default, Dec 18 2016, 07:03:39) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
