# Calling the same role from multiple playbooks

**URL:** <https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892>\
**Category:** Ansible Project\
**Created:** [January 2, 2020, 10:08pm UTC](https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892 "2020-01-02T22:08:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![audiolomb](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/audiolomb/32/7715_2.png) [@audiolomb](https://forum.ansible.com/u/audiolomb)\
**Post date:** [January 2, 2020, 10:08pm UTC](https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892/1 "2020-01-02T22:08:48Z")

</div>

Hello All.  
I am trying to solve the following issue.

- I have a SSSD role which configures my target machine via a .j2 template which contains a bunch of stuff, including the ldap\_access\_filter parameter.

- I also have playbooks organized hierarchically:

00-base.yml calls only playbooks (01-xxxx, 02-yyy, 03-zzz, etc.)

01-xxxx is called first, and sets up common stuff for all my machines (like basic firewall rules, subscription to satellite, etc.), including the configuration of sssd with the LDAP group that we use to administer our servers.

03-zzzz is a specialized playbook, that only applies to one or few instances. This playbook also needs to push additional LDAP groups so that people in those groups will be able to SSH into the target.

My problem is: if I call the SSSD role twice (playbook 01 and 03), the second configuration will wipe out the “01” one, effectively removing the LDAP group that was added initially.

I would like the 2 configurations to “merge” together so that the final configuration file will contain the LDAP groups defined in 01 and 03.

How would I accomplish this?

Thank you,  
Claudio

---

<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:** [January 3, 2020, 8:32am UTC](https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892/2 "2020-01-03T08:32:54Z")

</div>

Use the assemble module  
[https://docs.ansible.com/ansible/latest/modules/assemble\_module.html](https://docs.ansible.com/ansible/latest/modules/assemble_module.html)

---

<div class="post-metadata">

**Author:** ![Mehul\_Ved](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mehul\_Ved](https://forum.ansible.com/u/Mehul_Ved)\
**Post date:** [January 3, 2020, 8:33am UTC](https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892/3 "2020-01-03T08:33:42Z")

</div>

Have you had a look at [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_advanced\_syntax.html#yaml-anchors-and-aliases-sharing-variable-values](https://docs.ansible.com/ansible/latest/user_guide/playbooks_advanced_syntax.html#yaml-anchors-and-aliases-sharing-variable-values)?

---

<div class="post-metadata">

**Author:** ![audiolomb](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/audiolomb/32/7715_2.png) [@audiolomb](https://forum.ansible.com/u/audiolomb)\
**Post date:** [January 3, 2020, 7:52pm UTC](https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892/4 "2020-01-03T19:52:37Z")

</div>

I do not see on how either one of those solutions would work.

The assemble module concatenates files. My configuration needs to be merged, not concatenated…

---

<div class="post-metadata">

**Author:** ![audiolomb](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/audiolomb/32/7715_2.png) [@audiolomb](https://forum.ansible.com/u/audiolomb)\
**Post date:** [January 3, 2020, 7:53pm UTC](https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892/5 "2020-01-03T19:53:22Z")

</div>

I do not see on how either one of those solutions would work.

The assemble module concatenates files. My configuration needs to be merged, not concatenated…

---

<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:** [January 3, 2020, 8:06pm UTC](https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892/6 "2020-01-03T20:06:05Z")

</div>

Well, you wrote "merge" but you did not specify how you would like it to be "merged".  
"Merge" and concatenate share a lot of the same synonyms so concatenation was a valid answer like 10 others would be.

It you would like a more precise answer you should give more precise information about what exactly what you are trying to do.

---

<div class="post-metadata">

**Author:** ![audiolomb](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/audiolomb/32/7715_2.png) [@audiolomb](https://forum.ansible.com/u/audiolomb)\
**Post date:** [January 6, 2020, 4:22pm UTC](https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892/7 "2020-01-06T16:22:38Z")

</div>

My apologies if I was not clear.

Here is a better description (I hope!).

Let’s say there are 2 playbooks.

Playbook 1 does a bunch of stuff, including calling a role that sets the SSSD.conf with default settings, including the ldap\_access\_filter settings.

Then, playbook one “calls” playbook 2 to add additional “specialized” settings. However, also playbook 2 will need to change the sssd.conf, adding additional groups to the ldap\_access\_filter parameter.

If I call again the role that sets up sssd, then the settings that were applied by Playbook1 get overwritten by the ones in Playbook2.

I am stuck. I would like to keep the information in both playbooks and have a final sssd.conf that contains all the ldap groups declared.

I hope this makes sense.

please help! 🙂

Thank you,  
Claudio

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [January 6, 2020, 4:54pm UTC](https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892/8 "2020-01-06T16:54:23Z")

</div>

Let's try to minimise the problem. For example,

1) playbook A applies variable LDAP\_data\_A  
2) merge LDAP\_data\_A and LDAP\_data\_B into LDAP\_data  
3) playbook B applies variable LDAP\_data

Is this the scenario you're looking for? To proceed with the details post  
minimal examples of LDAP\_data\_A and LDAP\_data\_B. Post minimal example of the  
task (probably ldap\_attr ?).

HTH,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![mahespth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mahespth/32/252_2.png) [@mahespth](https://forum.ansible.com/u/mahespth)\
**Post date:** [January 6, 2020, 9:14pm UTC](https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892/9 "2020-01-06T21:14:57Z")

</div>

Hi,

Have you looked at ansible merge vars plugin?? We use this extensively with roles and it works well.

[https://pypi.org/project/ansible-merge-vars/](https://pypi.org/project/ansible-merge-vars/)

Cheers  
Steve

---

<div class="post-metadata">

**Author:** ![audiolomb](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/audiolomb/32/7715_2.png) [@audiolomb](https://forum.ansible.com/u/audiolomb)\
**Post date:** [January 6, 2020, 9:25pm UTC](https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892/10 "2020-01-06T21:25:27Z")

</div>

Do you have a practical example?

I am new here 😊

---

<div class="post-metadata">

**Author:** ![audiolomb](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/audiolomb/32/7715_2.png) [@audiolomb](https://forum.ansible.com/u/audiolomb)\
**Post date:** [January 7, 2020, 6:23pm UTC](https://forum.ansible.com/t/calling-the-same-role-from-multiple-playbooks/31892/11 "2020-01-07T18:23:43Z")

</div>

Ok so here is what I tried.

4 playbooks.

- 00.yml just calls 3 other playbooks:

- import\_playbook: ‘/opt/ansible/playbook/test/01.yml’

- import\_playbook: ‘/opt/ansible/playbook/test/02.yml’

- import\_playbook: ‘/opt/ansible/playbook/test/03.yml’

**01.yml:**
