<p><b>tl;dr</b></p>
<ol>
<li>playbooks can only have alphanumeric characters and underscores</li>
<li>run them with <code>ansible-playbook namespace.module.playbook_name_without_the_extension</code></li>
</ol>
<hr />
<p>The documentation provided by ansible is getting better:</p>
<p><a href="https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#using-a-playbook-from-a-collection" rel="nofollow noreferrer">https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#using-a-playbook-from-a-collection</a></p>
<p>doesn't quite explain why it wasn't working for you and you neglected to mention in your post the name of the playbook you were trying to run.</p>
<p>In experimenting to find the solution to this issue, I installed the power ibmi collection</p>
<p><code>ansible-galaxy collection install git+https://github.com/IBM/ansible-for-i.git
</code></p>
<p>it seemed odd that <code>ansible-playbook ibm.power_ibmi.ibmi-fix-repo-ptf-group</code> produced</p>
<p>this error</p>
<p><code> ERROR! the playbook: ibm.power_ibmi.ibmi-fix-repo-ptf-group could not be found</code></p>
<p>but</p>
<p><code>ansible-playbook ibm.power_ibmi.install_fix_repo_dependencies</code></p>
<p>did not,</p>
<p>the documentation for the roles directory <a href="https://docs.ansible.com/ansible/latest/dev_guide/developing_collections_structure.html#roles-directory" rel="nofollow noreferrer">https://docs.ansible.com/ansible/latest/dev_guide/developing_collections_structure.html#roles-directory</a> spells it out pretty clearly that the roles need to be underscores, not dashes, but the &quot;playbooks&quot; section is still TBD so it wouldn't have been that easy to figure out without trial and error</p>

CC BY-SA 4.0
2021-10-13T17:57:06.650Z
2021-10-13T17:57:06.650Z
Peter Turner
<p><a href="https://github.com/ansible/ansible/pull/67435" rel="nofollow noreferrer">this feature</a> was recently merged to ansible devel branch. It would be posible using:</p>
<pre><code>- import_playbook: testns.testcoll.default_collection_playbook
</code></pre>

CC BY-SA 4.0
2020-11-23T22:09:14.570Z
2020-11-23T22:09:14.570Z
jcespedes
<p>I'm trying to develop a reusable collection of playbooks that I can run from docker containers.  I don't want to share duplicate code between containers and I don't want to have containers that run multiple playbooks so what I'd like do develop is something where I have a</p>
<p><code>playbooks/doit.yml</code></p>
<p>file and a</p>
<p><code>.ansible/collections/playbooks/x/y/playbooks/thing-to-do.yml</code></p>
<p>playbook that I can import into my playbook</p>
<p>However, none of the documentation explains how to do that yet.</p>
<p>import playbooks doesn't say anything about collections</p>
<p><a href="https://docs.ansible.com/ansible/latest/modules/import_playbook_module.html" rel="nofollow noreferrer">https://docs.ansible.com/ansible/latest/modules/import_playbook_module.html</a></p>
<p>and playbooks collection documentation currently says tbd</p>
<p><a href="https://docs.ansible.com/ansible/latest/dev_guide/developing_collections.html#playbooks-directory" rel="nofollow noreferrer">https://docs.ansible.com/ansible/latest/dev_guide/developing_collections.html#playbooks-directory</a></p>
<p>I'm running ansible 2.9, I suppose I could import the playbook given the full path, but that seems like not what they're wanting me to do.</p>

CC BY-SA 4.0
2020-08-21T06:16:44.890Z
Sounds like you want a collection of roles instead of a collection of playbooks?
Bruce Becker
CC BY-SA 4.0
2020-08-21T11:43:55.457Z
@BruceBecker I might, but our software architect said if its specific to one type of device it goes a playbook - if it's something we can make generic we put it in a role. So I'm stuck with playbooks there.  Also, I'm jumping around between devices in the playbooks themselves and refreshing the inventory a few times (this implementation is to set up and configure a network of virtual machines and tie them in to our infrastructure so there's a lot of flitting about - need to ssh to about 15 devices in the playbooks all told)
Peter Turner
CC BY-SA 4.0
2020-08-21T11:55:04.107Z
no offence meant to your architect, but that doens't track well with me. Roles are meant to be re-usable. Playbooks are strategies, they invoke roles which execute relevant tasks based on what you're throwing them at. Abstract roles should be able to pick up different vars, depending on their targets, and still do the right thing. The devices should deliver  relevant facts about themselves to the roles. Using roles over playbooks gives you the explicit advantage of also being able to thoroughly test the roles. I know this may not sound helpful, but I hope it does :)
Bruce Becker
CC BY-SA 4.0
2020-08-21T12:25:13.943Z
It's good advice, I don't see any way around it until the powers that be flesh out what they mean by putting playbooks in collections.   I was poking around the source, doesn't seem to be any way to include those playbooks.  Even if I wanted to, I'd have to specify an absolute path to the playbooks in the collection.   Looking through a few pages of ansible collections repos on github I've found 0 instances of people trying to do this so I guess I'll just give up.  Not sure if this question is worth closing or if you want to just answer "don't do that"
Peter Turner
CC BY-SA 4.0
2020-08-21T12:54:26.133Z
You could use [import_playbook](https://docs.ansible.com/ansible/latest/modules/import_playbook_module.html), with judicious use of [lookup plugins](https://docs.ansible.com/ansible/latest/plugins/lookup.html#plugin-list) to find the right ones.
Bruce Becker
<ansible>
How are ansible playbooks supposed to be imported into a collection?
Peter Turner
# How are ansible playbooks supposed to be imported into a collection?

(Asked by: username_0 on 2020-08-21)

I'm trying to develop a reusable collection of playbooks that I can run from docker containers. I don't want to share duplicate code between containers and I don't want to have containers that run multiple playbooks so what I'd like do develop is something where I have a

`playbooks/doit.yml`

file and a

`.ansible/collections/playbooks/x/y/playbooks/thing-to-do.yml`

playbook that I can import into my playbook

However, none of the documentation explains how to do that yet.

import playbooks doesn't say anything about collections

<https://docs.ansible.com/ansible/latest/modules/import_playbook_module.html>

and playbooks collection documentation currently says tbd

<https://docs.ansible.com/ansible/latest/dev_guide/developing_collections.html#playbooks-directory>

I'm running ansible 2.9, I suppose I could import the playbook given the full path, but that seems like not what they're wanting me to do.

**Tags:** ansible

> **Comments:**
> **username_1**: Sounds like you want a collection of roles instead of a collection of playbooks?  
> **username_0**: @BruceBecker I might, but our software architect said if its specific to one type of device it goes a playbook - if it's something we can make generic we put it in a role. So I'm stuck with playbooks there.  Also, I'm jumping around between devices in the playbooks themselves and refreshing the inventory a few times (this implementation is to set up and configure a network of virtual machines and tie them in to our infrastructure so there's a lot of flitting about - need to ssh to about 15 devices in the playbooks all told)  
> **username_1**: no offence meant to your architect, but that doens't track well with me. Roles are meant to be re-usable. Playbooks are strategies, they invoke roles which execute relevant tasks based on what you're throwing them at. Abstract roles should be able to pick up different vars, depending on their targets, and still do the right thing. The devices should deliver  relevant facts about themselves to the roles. Using roles over playbooks gives you the explicit advantage of also being able to thoroughly test the roles. I know this may not sound helpful, but I hope it does :)  
> **username_0**: It's good advice, I don't see any way around it until the powers that be flesh out what they mean by putting playbooks in collections.   I was poking around the source, doesn't seem to be any way to include those playbooks.  Even if I wanted to, I'd have to specify an absolute path to the playbooks in the collection.   Looking through a few pages of ansible collections repos on github I've found 0 instances of people trying to do this so I guess I'll just give up.  Not sure if this question is worth closing or if you want to just answer "don't do that"  
> **username_1**: You could use [import_playbook](https://docs.ansible.com/ansible/latest/modules/import_playbook_module.html), with judicious use of [lookup plugins](https://docs.ansible.com/ansible/latest/plugins/lookup.html#plugin-list) to find the right ones.  

---

## 2 answers

### Answer by username_0 on 2021-10-13. Score: 0 | Accepted answer

**tl;dr**

1. playbooks can only have alphanumeric characters and underscores
2. run them with `ansible-playbook namespace.module.playbook_name_without_the_extension`

---

The documentation provided by ansible is getting better:

<https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#using-a-playbook-from-a-collection>

doesn't quite explain why it wasn't working for you and you neglected to mention in your post the name of the playbook you were trying to run.

In experimenting to find the solution to this issue, I installed the power ibmi collection

`ansible-galaxy collection install git+https://github.com/IBM/ansible-for-i.git`

it seemed odd that `ansible-playbook ibm.power_ibmi.ibmi-fix-repo-ptf-group` produced

this error

`ERROR! the playbook: ibm.power_ibmi.ibmi-fix-repo-ptf-group could not be found`

but

`ansible-playbook ibm.power_ibmi.install_fix_repo_dependencies`

did not,

the documentation for the roles directory <https://docs.ansible.com/ansible/latest/dev_guide/developing_collections_structure.html#roles-directory> spells it out pretty clearly that the roles need to be underscores, not dashes, but the "playbooks" section is still TBD so it wouldn't have been that easy to figure out without trial and error


---

### Answer by username_2 on 2020-11-23. Score: 1

this feature was recently merged to ansible devel branch. It would be posible using:
- import_playbook: testns.testcoll.default_collection_playbook


---

