# How can I pass a hash to a role?

**URL:** <https://forum.ansible.com/t/how-can-i-pass-a-hash-to-a-role/17346>\
**Category:** Ansible Project\
**Created:** [January 21, 2015, 11:56pm UTC](https://forum.ansible.com/t/how-can-i-pass-a-hash-to-a-role/17346 "2015-01-21T23:56:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Collin\_Allen](https://avatars.discourse-cdn.com/v4/letter/c/7993a0/32.png) [@Collin\_Allen](https://forum.ansible.com/u/Collin_Allen)\
**Post date:** [January 21, 2015, 11:56pm UTC](https://forum.ansible.com/t/how-can-i-pass-a-hash-to-a-role/17346/1 "2015-01-21T23:56:17Z")

</div>

Hi folks,

I’m running a playbook that makes use of a few custom roles, and one of them would benefit from being able to receive a YAML hash containing an arbitrary number of items (think: passing in a set of environment variables that should be set while running an executable). However, I’m failing to figure out what the syntax for doing this might be. Here’s where I’m at right now:

`

```auto

---

- hosts: webservers

  roles:

  - { role: app,

      role_var_1: somevalue,

      role_var_2: someothervalue,

      canidothis:

        ENV_VAR_1: /some/path

        ENV_VAR_1: /some/other/path

    }

```

`

But that’s not valid YAML syntax, apparently.

I’d like to be able to:

- Iterate over the list using the `template` module to emit key=value items from `canidothis`
- Access `canidothis.ENV_VAR_1` (or equivalent) in a task  
Am I missing some feature of YAML syntax that will let me accomplish this?

Thanks!

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 22, 2015, 12:14am UTC](https://forum.ansible.com/t/how-can-i-pass-a-hash-to-a-role/17346/2 "2015-01-22T00:14:50Z")

</div>

once you use shorthand mode you cannot regress to normal mode, this  
should work (or doing all in yaml normal):

---

<div class="post-metadata">

**Author:** ![Collin\_Allen](https://avatars.discourse-cdn.com/v4/letter/c/7993a0/32.png) [@Collin\_Allen](https://forum.ansible.com/u/Collin_Allen)\
**Post date:** [January 22, 2015, 7:19pm UTC](https://forum.ansible.com/t/how-can-i-pass-a-hash-to-a-role/17346/3 "2015-01-22T19:19:32Z")

</div>

Thanks! This helped!
