# Using include\_tasks with the same file several times inside a role

**URL:** <https://forum.ansible.com/t/using-include-tasks-with-the-same-file-several-times-inside-a-role/29753>\
**Category:** Ansible Project\
**Created:** [February 23, 2019, 2:57pm UTC](https://forum.ansible.com/t/using-include-tasks-with-the-same-file-several-times-inside-a-role/29753 "2019-02-23T14:57:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paulo\_Silva](https://avatars.discourse-cdn.com/v4/letter/p/dec6dc/32.png) [@Paulo\_Silva](https://forum.ansible.com/u/Paulo_Silva)\
**Post date:** [February 23, 2019, 2:57pm UTC](https://forum.ansible.com/t/using-include-tasks-with-the-same-file-several-times-inside-a-role/29753/1 "2019-02-23T14:57:12Z")

</div>

Hi,

Is it possible do to something like this inside a role?

- name: task with var1  
include\_tasks: external.yaml  
vars:  
my\_var=var1

- name task with var2  
include\_tasks: external.yaml  
vars:  
my\_var=var2

I’m no getting any error but it appears that only the first include\_tasks is used, switching to import\_tasks as the same behavior.

Is is expected? Any other to achieve this?

Thanks

---

<div class="post-metadata">

**Author:** ![BHARATHI\_DURAI\_RAJ](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@BHARATHI\_DURAI\_RAJ](https://forum.ansible.com/u/BHARATHI_DURAI_RAJ)\
**Post date:** [February 23, 2019, 3:22pm UTC](https://forum.ansible.com/t/using-include-tasks-with-the-same-file-several-times-inside-a-role/29753/2 "2019-02-23T15:22:38Z")

</div>

Try this one

- name: task with var1  
include\_tasks: external.yaml  
vars:  
my\_var: var1

- name: task with var2  
include\_tasks: external.yaml  
vars:  
my\_var: var2

---

<div class="post-metadata">

**Author:** ![Paulo\_Silva](https://avatars.discourse-cdn.com/v4/letter/p/dec6dc/32.png) [@Paulo\_Silva](https://forum.ansible.com/u/Paulo_Silva)\
**Post date:** [February 23, 2019, 10:07pm UTC](https://forum.ansible.com/t/using-include-tasks-with-the-same-file-several-times-inside-a-role/29753/3 "2019-02-23T22:07:54Z")

</div>

It was a typo, even like that only the first one is executed.

Regards

A sábado, 23/02/2019, 15:22, BHARATHI DURAI RAJ \<[cad.bharathi@gmail.com](mailto:cad.bharathi@gmail.com)\> escreveu:

---

<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:** [February 23, 2019, 10:20pm UTC](https://forum.ansible.com/t/using-include-tasks-with-the-same-file-several-times-inside-a-role/29753/4 "2019-02-23T22:20:19Z")

</div>

You have only shown us part of your code, since it's not working you have error(s) in that code.
