# Is it possible to use include\_tasks to run a tagged task in another file?

**URL:** <https://forum.ansible.com/t/is-it-possible-to-use-include-tasks-to-run-a-tagged-task-in-another-file/30536>\
**Category:** Ansible Project\
**Created:** [June 11, 2019, 5:39pm UTC](https://forum.ansible.com/t/is-it-possible-to-use-include-tasks-to-run-a-tagged-task-in-another-file/30536 "2019-06-11T17:39:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Douglas\_Thompson](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Douglas\_Thompson](https://forum.ansible.com/u/Douglas_Thompson)\
**Post date:** [June 11, 2019, 5:39pm UTC](https://forum.ansible.com/t/is-it-possible-to-use-include-tasks-to-run-a-tagged-task-in-another-file/30536/1 "2019-06-11T17:39:23Z")

</div>

I’m working on an ansible role and instead of putting all tasks in tasks/main.yml, I’d like to have separate files and use them sort of like functions. One of my files has all the possible tasks for file manipulation in a separate file. The thought would be to use tags to execute one of the tasks in that file.

In the example below I’ve put all the file manipulation tasks in a file called 'reboot\_me\_file.yml and would like to call just one task in main.yml when I need it. For example, ‘reboot\_me\_file.yml’ has three tagged tasks (create a file, stat a file, delete a file) and during the main.yml play, there will be a task, that includes say the ‘create a file’ task. I’ve looked at the following URL and it sounds like I can call a tagged task in the ‘reboot\_me\_file.yml’, but when I run the playbook, it executes all the tasks in ‘reboot\_me\_file.yml’

[https://docs.ansible.com/ansible/latest/modules/include\_tasks\_module.html#include-tasks-module](https://docs.ansible.com/ansible/latest/modules/include_tasks_module.html#include-tasks-module) (It says this should be available in ansible 2.7 but not which version of 2.7)

Anyone tried anything like this?

– ansible version: ansible 2.7.10

**– tasks/main.yml**

- name: Checking for an old ‘reboot\_me’ file  
include\_tasks:  
file: reboot\_me\_file.yml  
apply:  
tags:
- check\_reboot\_file

**– tasks/reboot\_me\_file.yml**

---

<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:** [June 11, 2019, 5:55pm UTC](https://forum.ansible.com/t/is-it-possible-to-use-include-tasks-to-run-a-tagged-task-in-another-file/30536/2 "2019-06-11T17:55:20Z")

</div>

> I'm working on an ansible role and instead of putting all tasks in  
> tasks/main.yml, I'd like to have separate files and use them sort of like  
> functions. One of my files has all the possible tasks for file manipulation  
> in a separate file. The thought would be to use tags to execute one of the  
> tasks in that file.
> 
> In the example below I've put all the file manipulation tasks in a file  
> called 'reboot\_me\_file.yml and would like to call just one task in main.yml  
> when I need it. For example, 'reboot\_me\_file.yml' has three tagged tasks  
> (create a file, stat a file, delete a file) and during the main.yml play,  
> there will be a task, that includes say the 'create a file' task. I've  
> looked at the following URL and it sounds like I can call a tagged task in  
> the 'reboot\_me\_file.yml', but when I run the playbook, it executes all the  
> tasks in 'reboot\_me\_file.yml'
> 
> [https://docs.ansible.com/ansible/latest/modules/include\_tasks\_module.html#include-tasks-module](https://docs.ansible.com/ansible/latest/modules/include_tasks_module.html#include-tasks-module)  
> (It says this should be available in ansible 2.7 but not which version of  
> 2.7)

It doesn't, it says "will be applied to the tasks within the include."

> Anyone tried anything like this?

Many have, all have failed, since it doesn't work like that.  
All tags in a file is always added to the task, at this level it is not a filter.

To choose which tags to run is done at the command line with -t/--tags

---

<div class="post-metadata">

**Author:** ![Douglas\_Thompson](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Douglas\_Thompson](https://forum.ansible.com/u/Douglas_Thompson)\
**Post date:** [June 11, 2019, 5:57pm UTC](https://forum.ansible.com/t/is-it-possible-to-use-include-tasks-to-run-a-tagged-task-in-another-file/30536/3 "2019-06-11T17:57:29Z")

</div>

OK. I’ll just break out the tasks into separate files.  
Thanks for the reply,
