0

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.

5
  • Sounds like you want a collection of roles instead of a collection of playbooks? Aug 21 '20 at 6:16
  • @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
    Aug 21 '20 at 11:43
  • 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 :) Aug 21 '20 at 11:55
  • 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
    Aug 21 '20 at 12:25
  • You could use import_playbook, with judicious use of lookup plugins to find the right ones. Aug 21 '20 at 12:54
1

this feature was recently merged to ansible devel branch. It would be posible using:

- import_playbook: testns.testcoll.default_collection_playbook
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.