# passing parameters to roles

**URL:** <https://forum.ansible.com/t/passing-parameters-to-roles/22914>\
**Category:** Ansible Project\
**Created:** [October 28, 2016, 4:56pm UTC](https://forum.ansible.com/t/passing-parameters-to-roles/22914 "2016-10-28T16:56:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neil\_Watson](https://avatars.discourse-cdn.com/v4/letter/n/dbc845/32.png) [@Neil\_Watson](https://forum.ansible.com/u/Neil_Watson)\
**Post date:** [October 28, 2016, 4:56pm UTC](https://forum.ansible.com/t/passing-parameters-to-roles/22914/1 "2016-10-28T16:56:43Z")

</div>

Greetings,

I’m trying to pass a data structure to a role, but it’s not working out. What have I done wrong?

main.yml:

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 28, 2016, 6:44pm UTC](https://forum.ansible.com/t/passing-parameters-to-roles/22914/2 "2016-10-28T18:44:20Z")

</div>

First you define image in the vars section, and then you overwrite image with itself when you call the role, you can't do that.

---

<div class="post-metadata">

**Author:** ![Neil\_Watson](https://avatars.discourse-cdn.com/v4/letter/n/dbc845/32.png) [@Neil\_Watson](https://forum.ansible.com/u/Neil_Watson)\
**Post date:** [October 28, 2016, 6:53pm UTC](https://forum.ansible.com/t/passing-parameters-to-roles/22914/3 "2016-10-28T18:53:25Z")

</div>

My intention is to pass it to the role not redefine it. What do you suggest?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 28, 2016, 8:08pm UTC](https://forum.ansible.com/t/passing-parameters-to-roles/22914/4 "2016-10-28T20:08:48Z")

</div>

You have a few options.  
You don't need to pass them to the role, variables is global so you can use them directly in the role, image.one.state and image.one.path.

Instead of using the image variable in the role, you can rename it to img. But since variables is global in Ansible I would recommend to prefix variables in a role with the role name, so you could use test\_image in the role.
