# Pass complex variables into roles

**URL:** <https://forum.ansible.com/t/pass-complex-variables-into-roles/21985>\
**Category:** Ansible Project\
**Created:** [July 11, 2016, 2:09pm UTC](https://forum.ansible.com/t/pass-complex-variables-into-roles/21985 "2016-07-11T14:09:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Bruno](https://avatars.discourse-cdn.com/v4/letter/e/c5a1d2/32.png) [@Eric\_Bruno](https://forum.ansible.com/u/Eric_Bruno)\
**Post date:** [July 11, 2016, 2:09pm UTC](https://forum.ansible.com/t/pass-complex-variables-into-roles/21985/1 "2016-07-11T14:09:44Z")

</div>

Hi folks,

I’m facing an issue with roles call in plays when passing complex var. I want to find a way to pass variable by reference like so:

`  
#group\_vars/python-app/fooapi.yml

fooapi:  
uno: 1  
dos: 2

`  
#group\_vars/python-app/barapi.yml

fooapi:  
uno: 1000  
dos: 2000

`

`

`  
#play.yml

- hosts: python-app  
roles:
- { role: python, app: fooapi}  
`- { role: python, app: barapi}`

`

`  
#roles/python/tasks/main.yml

- debug: var=app

`

This is maybe a bad practice but if we found a solution, this is a very usefull and nice way to do what I want to do.

Thank you for your help 🙂

---

<div class="post-metadata">

**Author:** ![Eric\_Bruno](https://avatars.discourse-cdn.com/v4/letter/e/c5a1d2/32.png) [@Eric\_Bruno](https://forum.ansible.com/u/Eric_Bruno)\
**Post date:** [July 18, 2016, 9:14am UTC](https://forum.ansible.com/t/pass-complex-variables-into-roles/21985/2 "2016-07-18T09:14:54Z")

</div>

Hi folks,

Maybe there is no solution for that exactly. I want to make a role that is completly free from looping over a list of complex map like so:

`

# group\_vars/python-app/apps.yml

-python\_apps:

- name: foo  
uno: 1  
dos: 2  
[…]
- name: bar  
uno: 1000  
dos: 2000  
[…]

`

`

# roles/python-apps/tasks/main.yml

- include: install.yml  
with\_items: “{{python\_apps}}”  
tags:
- python-apps
- install

`

`

# roles/python-apps/tasks/install.yml

- debug: var={{item.name}}

`

The role itself is maintenable, but the group\_vars file containing all complex data structures will become huge and hard to maintain. What do you do in this case?

Thanks !  
Kindly
