# playing a role multiple time with variable

**URL:** <https://forum.ansible.com/t/playing-a-role-multiple-time-with-variable/13027>\
**Category:** Ansible Project\
**Created:** [June 27, 2013, 1:56pm UTC](https://forum.ansible.com/t/playing-a-role-multiple-time-with-variable/13027 "2013-06-27T13:56:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julien\_Tognazzi](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@Julien\_Tognazzi](https://forum.ansible.com/u/Julien_Tognazzi)\
**Post date:** [June 27, 2013, 1:56pm UTC](https://forum.ansible.com/t/playing-a-role-multiple-time-with-variable/13027/1 "2013-06-27T13:56:11Z")

</div>

Hi all,

I created a tomcat role to create a tomcat instance.  
And I’m wondering what is the best way to pass the instance parameters to it ?

My playbook looks like :

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 27, 2013, 2:49pm UTC](https://forum.ansible.com/t/playing-a-role-multiple-time-with-variable/13027/2 "2013-06-27T14:49:08Z")

</div>

You will be able to do things like {{ instance.http\_port }}

---

<div class="post-metadata">

**Author:** ![Julien\_Tognazzi](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@Julien\_Tognazzi](https://forum.ansible.com/u/Julien_Tognazzi)\
**Post date:** [June 27, 2013, 4:05pm UTC](https://forum.ansible.com/t/playing-a-role-multiple-time-with-variable/13027/3 "2013-06-27T16:05:00Z")

</div>

hum,

It doesn’t seem to work…  
In template I get empty field  
and in tasks I have the following error:

TASK: [Create instance user] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [146.159.230.242] =\> {“failed”: true, “item”: “”, “name”: “jira”, “rc”: 3}  
msg: useradd: invalid user ID ‘{{instance.uid}}’

with the following task:

- name: Create instance user  
user: name=$instance uid={{ instance.uid }} groups=tomcat home={{ instance.home }}/{{ instance }} system=yes

What am I doing wrong then ?

thanks

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 27, 2013, 4:21pm UTC](https://forum.ansible.com/t/playing-a-role-multiple-time-with-variable/13027/4 "2013-06-27T16:21:15Z")

</div>

Oh, got it.

In this case the parameterized role is a string, ‘myinstance1’, which is causing the problem.

It might not work, in which case I’ll have to make some changes, but I suppose you may wish to try:

instance: ${myinstance1}

Which should be sufficient to reference the other variable.

I don’t recall offhand if this will fly:

instance: "{{ myinstance1 }}

If you are just going to apply a list of all defined instances, you might just want to have one tomcat role instead, and have it use “with\_items” on the instances list variable, and loop through them inside the role instead.

This might be easier.

---

<div class="post-metadata">

**Author:** ![Julien\_Tognazzi](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@Julien\_Tognazzi](https://forum.ansible.com/u/Julien_Tognazzi)\
**Post date:** [June 28, 2013, 7:27am UTC](https://forum.ansible.com/t/playing-a-role-multiple-time-with-variable/13027/5 "2013-06-28T07:27:07Z")

</div>

Many thanks !

Now I see my mistake…

Julien,
