Molecule: Playbook Testing - Enhancement/New Feature Request

Created on 5 Aug 2016  路  7Comments  路  Source: ansible-community/molecule

As molecule is able to run a playbook with the role from the init action, can it be extended to run a playbook which in it's basic level just contains roles but may also contain tasks.

It would be great if we could be able to test playbooks as I have a bunch of custom roles that depend on my other roles hence can't be tested independently rather only in a playbook. 馃槂

Most helpful comment

@retr0h the mentioned link is outdated. Could you provide the new link? Sadly I could not find any other reference for this functionality than your post.

All 7 comments

molecule uses a playbook to test the role. If you have complicated setup requirements, you can get creative in this playbook. If you merely have dependency roles, then list them in the dependencies section of the meta/main.yml of the your running molecule against and all should be well.

If I have misunderstood your difficulty, please elaborate.

I know it runs a playbook, but in a situation where you have custom roles, roles from galaxy and tasks and your end goal is to provision a complete system it becomes complicated. For instance I have playbooks that will run 10+ roles and at the end I get a fully functioning system as part of my stack. Now the playbooks may contain roles that need to run before others do or that get their input from the outputs of other roles in which case dependency alone is not enough.

Right now this is my workflow;

  • create roles
  • test roles that are independent with molecule
  • create playbook containing tested and untested roles
  • spin up an EC2 in AWS or Vagrant Box manually
  • run the playbook and hope for the best

    • if successful; run the playbook again to check for idempotent

    • if passed idempotent test, manually install testinfra on the machine and write test.py and test

    • if unsuccessful; destroy machine, go back to drawing board

Molecule does a great job at automating the creation of a test machine (vagrant or docker), testing a role does what it should do (via testinfra or serverspec) and also idempotent test.

So now molecule does testing of roles how hard will it be to test a playbook which contains roles

The workflow will be something like this;

  • molecule playbook init: this is where all the logic will be; folder structure, .molecule.yml etc
  • i then edit playbook.yml and 200+ lines of roles and tasks
  • launch vagrant/docker
  • run user created playbook containing 15+ roles for example (checking that each role succeeds)
  • run playbook again
  • run user created test.py
  • destroy test machine

Let me know your thoughts. It just seems logical that if you can test roles you should be able to test playbooks regardless of how complex they are.

So you are asking if molecule could test a playbook, and that playbook may consist of numerous roles and tasks. You don't want to test a single role with a single playbook (you're already doing that), but more of a playbook that tests the integration of various components. Right?

Yes, precisely. Same thing it does now but on a grander level with playbooks.

You can do that today, allow molecule to know you are leveraging a requirements file, and it will automatically download your roles.

ansible:
  requirements_file: requirements.yml

_or_

Simply tell molecule where the other roles are.

https://github.com/metacloud/molecule/blob/master/tests/functional/docker/scenarios/full/molecule.yml#L2-L4

I usually use the latter approach. I have a directory with a bunch of roles in it, then I write "scenario" directories, which simply have a molecule.yml and playbook.yml that exercise all of my roles in conjunction. I then write tests to assert the outcome of the integration.

Cool... I'll give that a go!

@retr0h the mentioned link is outdated. Could you provide the new link? Sadly I could not find any other reference for this functionality than your post.

Was this page helpful?
0 / 5 - 0 ratings