# On the same server, how to run a role twice with different arguments

**URL:** <https://forum.ansible.com/t/on-the-same-server-how-to-run-a-role-twice-with-different-arguments/17808>\
**Category:** Ansible Project\
**Created:** [March 22, 2015, 10:38pm UTC](https://forum.ansible.com/t/on-the-same-server-how-to-run-a-role-twice-with-different-arguments/17808 "2015-03-22T22:38:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olivier\_Lauret](https://avatars.discourse-cdn.com/v4/letter/o/b3f665/32.png) [@Olivier\_Lauret](https://forum.ansible.com/u/Olivier_Lauret)\
**Post date:** [March 22, 2015, 10:38pm UTC](https://forum.ansible.com/t/on-the-same-server-how-to-run-a-role-twice-with-different-arguments/17808/1 "2015-03-22T22:38:07Z")

</div>

Hello all,

I am new with ansible and trying to understand how, on the same server, to run a role twice with different arguments.

What I am trying to do is to install twice the same software but using a different path.

I have tried to use the host file like:

[grp1]  
192.168.1.10

[grp2]  
192.168.1.10

and then set the group\_vars like:

group\_vars/grp1:

---

<div class="post-metadata">

**Author:** ![George\_Boobyer](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@George\_Boobyer](https://forum.ansible.com/u/George_Boobyer)\
**Post date:** [March 23, 2015, 6:17pm UTC](https://forum.ansible.com/t/on-the-same-server-how-to-run-a-role-twice-with-different-arguments/17808/2 "2015-03-23T18:17:49Z")

</div>

The group vars will overwrite each other - if a host is in two groups that share vars.  
Try putting a dictionary car in the host vars for the host:

install\_paths:  
&nbsp;&nbsp;- '/opt/install1'  
&nbsp;&nbsp;- '/opt/install2'

Then in the task use with\_items: install\_paths (not sure what task you are using so here using the copy module for example)

- copy  
&nbsp;&nbsp;&nbsp;src: localsrc  
&nbsp;&nbsp;&nbsp;dest: "{item}"  
&nbsp;&nbsp;&nbsp;with\_items: install\_paths

That should do it as item is replaces with each element in the with\_items.

---

<div class="post-metadata">

**Author:** ![George\_Boobyer](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@George\_Boobyer](https://forum.ansible.com/u/George_Boobyer)\
**Post date:** [March 23, 2015, 6:19pm UTC](https://forum.ansible.com/t/on-the-same-server-how-to-run-a-role-twice-with-different-arguments/17808/3 "2015-03-23T18:19:04Z")

</div>

Darn auto correct - should read dictionary var not car in the above! ; )

George

---

<div class="post-metadata">

**Author:** ![Jonathan\_Davila](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@Jonathan\_Davila](https://forum.ansible.com/u/Jonathan_Davila)\
**Post date:** [March 23, 2015, 7:18pm UTC](https://forum.ansible.com/t/on-the-same-server-how-to-run-a-role-twice-with-different-arguments/17808/4 "2015-03-23T19:18:49Z")

</div>

Another method you could use is passing the variable value directly into the role when you call it as such

`---`  
`- name: SomePlaybook`  
`hosts: yourgroup`  
`roles:`

- {role: yourrole, install\_path: ‘/opt/install1’ }
- {role: yourrole, install\_path: ‘/opt/install2’ }

---

<div class="post-metadata">

**Author:** ![Olivier\_Lauret](https://avatars.discourse-cdn.com/v4/letter/o/b3f665/32.png) [@Olivier\_Lauret](https://forum.ansible.com/u/Olivier_Lauret)\
**Post date:** [March 23, 2015, 11:03pm UTC](https://forum.ansible.com/t/on-the-same-server-how-to-run-a-role-twice-with-different-arguments/17808/5 "2015-03-23T23:03:22Z")

</div>

Thank you George and Jonathan for your feedback,

I like the idea of the roles in the playbook as the installation is a bit more complex than explained in the email. Thank you for the tip, I will try it write now 🙂

Regards,  
Olivier

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [March 28, 2015, 5:53pm UTC](https://forum.ansible.com/t/on-the-same-server-how-to-run-a-role-twice-with-different-arguments/17808/6 "2015-03-28T17:53:23Z")

</div>

Obvious for some, helpful for others, a more condensed version could look like:

` `—` `- name: SomePlaybook` `hosts: yourgroup` `roles:`

- { role: yourrole, install\_path: [‘/opt/install1’, ‘/opt/install2’] }

`
