# Issue with using task files/playbook in ad hoc commands and in roles

**URL:** <https://forum.ansible.com/t/issue-with-using-task-files-playbook-in-ad-hoc-commands-and-in-roles/33992>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [October 9, 2020, 9:21am UTC](https://forum.ansible.com/t/issue-with-using-task-files-playbook-in-ad-hoc-commands-and-in-roles/33992 "2020-10-09T09:21:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mouton\_Noir](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@Mouton\_Noir](https://forum.ansible.com/u/Mouton_Noir)\
**Post date:** [October 9, 2020, 9:21am UTC](https://forum.ansible.com/t/issue-with-using-task-files-playbook-in-ad-hoc-commands-and-in-roles/33992/1 "2020-10-09T09:21:08Z")

</div>

Hi,

Newbie to Ansible, but I already made a lot of things with it.  
One thing, though, I can’t do is re-use a task file for adhoc commands or re-use a playbook in another playbook :

For example, I use a task file (R\_packages.yml) in a role, that starts like this :

- name: Recuperation de la version de R installee  
win\_shell: (Get-ItemProperty HKLM:Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object DisplayName -like “R for Win\*”).DisplayVersion  
register: Rversion

I’d like to be able to launch it with an ad hoc command like :

ansible-playbook R\_packages.yml …  
But it doesn’t work :

ERROR! ‘register’ is not a valid attribute for a Play

I had to create a playbook to launch it :

- hosts: fst-win-tp-bio  
gather\_facts: “false”  
tasks:
- name: Install packages R  
import\_tasks: /etc/ansible/roles/fst-win-tp-bio/tasks/R\_packages.yml

I didn’t fond anything in the doc that makes me understand how I could make an “hybrid” task/playbook file I could launch both ways

To be clear : This task file is part of a role, and I like to be able to use it from times to times on adhoc command.

Thanks for your help  
E.T.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 9, 2020, 9:58am UTC](https://forum.ansible.com/t/issue-with-using-task-files-playbook-in-ad-hoc-commands-and-in-roles/33992/2 "2020-10-09T09:58:44Z")

</div>

ansible-playbook is meant to run..... ansible playbooks 🙂

What you have is a task file.  
Playbooks contain tasks. Playbook can import/include tasks files.  
To run a playbook you do need the playbook items such as hosts, tasks, etc.

---

<div class="post-metadata">

**Author:** ![Mouton\_Noir](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@Mouton\_Noir](https://forum.ansible.com/u/Mouton_Noir)\
**Post date:** [October 9, 2020, 11:53am UTC](https://forum.ansible.com/t/issue-with-using-task-files-playbook-in-ad-hoc-commands-and-in-roles/33992/3 "2020-10-09T11:53:19Z")

</div>

I was hoping, maybe I could pass the missing items in ansible-playbook arguments.  
The problem is the hosts item : in the playbook used to launch a task file, you tend to give a large scope to it, and I find it dangerous, if one forget the -l parameter in the adhoc command.  
I was searching a way to avoid specify hosts in the playbook, what would oblige to pass it in arguments.

Thanks for your answer  
E.T.
