# roles and compound vars

**URL:** <https://forum.ansible.com/t/roles-and-compound-vars/14830>\
**Category:** Ansible Project\
**Created:** [March 22, 2014, 6:21am UTC](https://forum.ansible.com/t/roles-and-compound-vars/14830 "2014-03-22T06:21:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Bozanich](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@Adam\_Bozanich](https://forum.ansible.com/u/Adam_Bozanich)\
**Post date:** [March 22, 2014, 6:21am UTC](https://forum.ansible.com/t/roles-and-compound-vars/14830/1 "2014-03-22T06:21:27Z")

</div>

I’m having trouble figuring out how to pass non-string parameters to roles.

I’ve tried a few different methods, with the most recent using “vars\_files” in the play:

[https://github.com/boz/ansible-deploy/blob/multiplay/playbook.yml#L45](https://github.com/boz/ansible-deploy/blob/multiplay/playbook.yml#L45)

This only seems to import the variables into the play; the variables defined in the vars file aren’t visible in the roles.

Ideally I’d be able to parametrize roles with a reference to a compound variable. I’ve tried this, but the roles only receive a stringified version of the hash that I pass in.

The only other options I can see at this point are either passing in a large amount of parameters every time or creating an extra role for every “abstract” role that I want to invoke. Neither of these sound very appealing and so I’m hoping that there’s something that I’m missing. Ideas?

Thanks,  
-Adam

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 24, 2014, 2:49pm UTC](https://forum.ansible.com/t/roles-and-compound-vars/14830/2 "2014-03-24T14:49:04Z")

</div>

```auto

If you really mean passing parameters to roles:

roles:

   # short form
   - webserver
   # long form
   - { role: dbserver, port: 4200, foo: [1,2,3] }

vars_files of course works too, I'd need to see your vars_file to see what you might have wrong in it.

```

---

<div class="post-metadata">

**Author:** ![Adam\_Bozanich](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@Adam\_Bozanich](https://forum.ansible.com/u/Adam_Bozanich)\
**Post date:** [April 1, 2014, 1:50am UTC](https://forum.ansible.com/t/roles-and-compound-vars/14830/3 "2014-04-01T01:50:25Z")

</div>

Thanks, Michael.

I had wanted to be able to pass an entire dict by name into a role, but apparently that isn’t possible.

I’ve gotten things to work with vars\_files, I’ll try restructuring things to work with this.

Cheers,  
-Adam

---

<div class="post-metadata">

**Author:** ![C\_Morgan\_Hamill](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@C\_Morgan\_Hamill](https://forum.ansible.com/u/C_Morgan_Hamill)\
**Post date:** [April 1, 2014, 1:48pm UTC](https://forum.ansible.com/t/roles-and-compound-vars/14830/4 "2014-04-01T13:48:50Z")

</div>

Excerpts from Adam Bozanich's message of 2014-03-31 21:50:25 -0400:

> I had wanted to be able to pass an entire dict by name into a role, but  
> apparently that isn't possible.

I \*believe\* recent versions of Ansible will allow:

&nbsp;&nbsp;&nbsp;&nbsp;- { role: my role, myrolevars: "{{ some\_dict\_defined\_elsewhere }}"
