Calling a Role within a Role with multiple times and with each time a different values

17 views
Skip to first unread message

Som Das

unread,
Sep 9, 2021, 12:12:12 PM9/9/21
to Ansible Development
Hi All,

I need to call a Ansible role Multiple times within a role and each time I need to pass different set of values via extra vars.


Anybody has any solution to it?


Regards,
Somarko Das 

Didier BOURRIAUD

unread,
Sep 9, 2021, 12:19:32 PM9/9/21
to Som Das, Ansible Development
Hi,

To do that, I think you need to call it with the module "include_role" in the tasks. This is called Dynamic Reuse.

Example :
tasks:
- name: "First Time"
include_role:
name: "my_role"
vars:
key1: "value"
- name: "Second Time"
include_role:
name: "my_role"
vars:
key1: "Another Value"

Hope this helps.

--

Kosmos

Didier BOURRIAUD 
Expert Technique
Tél. : 0684187621 8 rue Kervégan 44000 Nantes - France

Twitter   Linkedin   Youtubewww.kosmos-education.com


--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/9afce483-e5eb-45c4-86d8-af9312f10fe7n%40googlegroups.com.

Som Das

unread,
Sep 9, 2021, 12:30:03 PM9/9/21
to Ansible Development
Hi Didier,

Thanks for the prompt reply,

This is where we are statically passing, I mean this is hardcoded, the values but in my scenario end-user will decide what values to pass


Thanks & Regards,
Som Das

Reply all
Reply to author
Forward
0 new messages