# Need help for some logic

**URL:** <https://forum.ansible.com/t/need-help-for-some-logic/32753>\
**Category:** Ansible Project\
**Created:** [April 22, 2020, 7:35am UTC](https://forum.ansible.com/t/need-help-for-some-logic/32753 "2020-04-22T07:35:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rahul\_Kumar1](https://forum.ansible.com/u/Rahul_Kumar1)\
**Post date:** [April 22, 2020, 7:35am UTC](https://forum.ansible.com/t/need-help-for-some-logic/32753/1 "2020-04-22T07:35:32Z")

</div>

Hi Ansible Gurus,

I have below playbook in one git repository: mymasterplaybook.yml

- name: Do some test  
include\_role:  
name: mytestrole  
tasks\_from: test-server-names  
when: “‘testing-group-name’ in group\_names”`

Now I invoke above playbook with a existing role named “mytestrole” and task in it as “test-server-names” and group name is testing-group-name.It works fine.

Now what i want tasks\_from , name of role and group name as dynamic : so my mymasterplaybook.yml will look like as below

- name: Do some test  
include\_role:  
name: {{dynamic role name}  
tasks\_from: {{dynamic task name from role}}  
when: “{{dynamic group name}’ in group\_names”`

so that any role can be plugged into that !  
So whenever some one writes roles , they write 2 things

1. Role
2. some configuration file which contains “dynamic role name”, “dynamic task name from role”, “dynamic group name” as configurable items so that it can be plugged in master playbook named mymasterplaybook.yml as shown above.  
and this configuration file will work as an interface between role and master playbook (named mymasterplaybook.yml) for entire execution.

Rahul

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 22, 2020, 7:41am UTC](https://forum.ansible.com/t/need-help-for-some-logic/32753/2 "2020-04-22T07:41:59Z")

</div>

> Hi Ansible Gurus,  
> I have below playbook in one git repository: mymasterplaybook.yml  
> - name: Do some test  
> include\_role:  
> name: mytestrole  
> tasks\_from: test-server-names  
> when: "'testing-group-name' in group\_names"`
> 
> Now I invoke above playbook with a existing role named "mytestrole" and task in it as "test-server-names" and group  
> name is testing-group-name.It works fine.
> 
> Now what i want tasks\_from , name of role and group name as dynamic : so my mymasterplaybook.yml will look like as below  
> - name: Do some test  
> include\_role:  
> name: {{dynamic role name}  
> tasks\_from: {{dynamic task name from role}}  
> when: "{{dynamic group name}' in group\_names"`
> 
> so that any role can be plugged into that !  
> So whenever some one writes roles , they write 2 things  
> 1. Role  
> 2. some configuration file which contains "dynamic role name", "dynamic task name from role", "dynamic group name" as  
> configurable items so that it can be plugged in master playbook named mymasterplaybook.yml as shown above.  
> and this configuration file will work as an interface between role and master playbook (named mymasterplaybook.yml) for  
> entire execution.
> 
> Rahul

Yes, and what's your question(s) ?

The when condition wouldn't work that way as the value is virtually wrapped into a Jinja template, so try:

when: dynamic\_group\_name in group\_names

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Rahul\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rahul\_Kumar1](https://forum.ansible.com/u/Rahul_Kumar1)\
**Post date:** [April 22, 2020, 7:58am UTC](https://forum.ansible.com/t/need-help-for-some-logic/32753/3 "2020-04-22T07:58:42Z")

</div>

Thanks stefan !

My question how i can take these 3 dynamic values as a configuration file which comes with each role.  
Example: I want to invoke mymasterplaybook.yml for 10 roles , so i invoke this playbook  
as \>ansible-playbook -i inventory.yml mymasterplaybook.yml → This invocation could be completed if mymasterplaybook.yml takes those 3 params which are dynamic from some configuration file a below

---

<div class="post-metadata">

**Author:** ![Rahul\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rahul\_Kumar1](https://forum.ansible.com/u/Rahul_Kumar1)\
**Post date:** [April 22, 2020, 8:14am UTC](https://forum.ansible.com/t/need-help-for-some-logic/32753/4 "2020-04-22T08:14:06Z")

</div>

In short , I want this configuration file as an interface between mymasterplaybook.yml and individual roles , also mymasterplaybook.yml need to recognize this file to fill its dynamic params .

Rahul

---

<div class="post-metadata">

**Author:** ![Rahul\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rahul\_Kumar1](https://forum.ansible.com/u/Rahul_Kumar1)\
**Post date:** [April 22, 2020, 4:57pm UTC](https://forum.ansible.com/t/need-help-for-some-logic/32753/5 "2020-04-22T16:57:04Z")

</div>

Ansible gurus, any suggestions?
