# Dynamic reusability of a playbook — include\_tasks, include\_role, import\_playbook …  Mission impossible?

**URL:** <https://forum.ansible.com/t/dynamic-reusability-of-a-playbook-include-tasks-include-role-import-playbook-mission-impossible/26649>\
**Category:** Ansible Project\
**Created:** [February 2, 2018, 8:53pm UTC](https://forum.ansible.com/t/dynamic-reusability-of-a-playbook-include-tasks-include-role-import-playbook-mission-impossible/26649 "2018-02-02T20:53:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stas\_Fomin](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@Stas\_Fomin](https://forum.ansible.com/u/Stas_Fomin)\
**Post date:** [February 2, 2018, 8:53pm UTC](https://forum.ansible.com/t/dynamic-reusability-of-a-playbook-include-tasks-include-role-import-playbook-mission-impossible/26649/1 "2018-02-02T20:53:33Z")

</div>

Hello all.

Consider following sample project:  
[https://github.com/belonesox/ansible\_dynamic\_role\_howto](https://github.com/belonesox/ansible_dynamic_role_howto)

With tree:  
.  
├── playbook.yml  
├── run-playbook  
└── somedir  
└── dynamically\_defined\_dir  
├── do.yml  
├── roles  
│ ├── role1  
│ ├── role2  
│ │ ├── defaults  
│ │ │ └── main.yml  
│ │ ├── tasks  
│ │ │ └── main.yml  
│ │ └── templates  
│ │ └── sometemplate.j2  
│ └── role3  
├── run-nested-playbook  
├── templates  
└── vars

Here we have here:

- A working playbook “do.yml” in “dynamically\_defined\_dir” (can be run by “run-nested-playbook” shell script).
- A playbook “playbook.yml” that tried to use “nested” playbook “do.yml”, trying to redefine some of defaults of nested playbook.
- Playbook “playbook.yml” should be run (“run-playbook”) with some external parameters like this:  
ansible-playbook -vvv -i ‘localhost,’ -c local playbook.yml --extra-vars “external\_extra\_var=somedir”

Expected (wanted) result for “run-playbook”

- Get contents of sometemplate.j2 with replacing default variables to some variables/parameters from “playbook.yml”
- “Playbook.yml” should be without hardcoding paths to nested playbook (should be calculated somehow from “–extra-vars”). Better by “set\_fact” some variable, and reuse it.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [February 5, 2018, 3:14pm UTC](https://forum.ansible.com/t/dynamic-reusability-of-a-playbook-include-tasks-include-role-import-playbook-mission-impossible/26649/2 "2018-02-05T15:14:43Z")

</div>

There are further changes to dynamic inclusion of tasks in ansible 2.5, so probably worth while testing with latest code rather 2.4.x versions now.

see [https://docs.ansible.com/ansible/devel/porting\_guide\_2.5.html](https://docs.ansible.com/ansible/devel/porting_guide_2.5.html)  
and [https://groups.google.com/forum/#!topic/ansible-project/GsJ7GjUhI\_g](https://groups.google.com/forum/#!topic/ansible-project/GsJ7GjUhI_g) regarding testing out 2.5 alpha build.

Hope this helps,

Jon
