Molecule is a tool originally developed by retr0h and now maintained by Ansible/Red Hat that automates testing of Ansible roles. Instead of a highly manual process, testing a role against any number of distros is as simple as running molecule test. Molecule has many drivers for testing your role on different kinds of infrastructure such as Docker, Vagrant and EC2. I suggest using the Docker driver since spinning up and tearing down instances is orders of magnitude faster than other drivers.
In this tutorial video I build a super simple redis role to show how you can use Molecule for both development and testing.
– 1:09 — Setup & Get Started
– 2:26 — Empty Molecule Project
– 4:05 — Test the New Role
– 7:08 — Role Development Workflow
– 8:49 — Running on Multiple Platforms
– 10:02 — Start Developing Redis Role
– 11:49 — Write Your First Test
– 14:07 — Manage Services on Docker
– 16:07 — Converge On New Images
– 16:49 — Test Services Are Started
– 17:50 — Using a Non-Root User
MORE INFO
ā
READ THE IN-DEPTH TUTORIAL HERE == http://bit.ly/2SBKQVJ
ā
Jeff Geerling’s Images on Docker Hub == https://hub.docker.com/u/geerlingguy
ā
My Images on Docker Hub == https://hub.docker.com/u/percygrunwald
ā
Molecule on GitHub == https://github.com/ansible/molecule/
ā
TestInfra on ReadTheDocs == https://testinfra.readthedocs.io/en/latest/
SETUP/EDITOR/IDE
ā
Visual Studio Code (https://code.visualstudio.com/)
ā
Ansible extension by Microsoft (http://bit.ly/2SdnqoK).
Thanks for watching and hope it’s entertaining/useful for you! Hit me up in the comments if you have any questions or feedback šŖ.
Related & Channel
ā¶ļø http://bit.ly/2VWid3D == Playlist of all Ansible videos
āļø http://bit.ly/2HavqCu == Subscribe to our YouTube Channel
Our Site & Socials
š http://bit.ly/2shtKwZ == TopTechSkills.com
š¦ http://bit.ly/2RkgZkk == @TopTechSkills on Twitter
š¦ http://bit.ly/2AA19aN == @PercyGrunwald on Twitter
š http://bit.ly/2ACQgEW == @TopTechSkills on Facebook
š¹ http://bit.ly/2CWR3ST == @PercyGrunwald on Twitch
source
Hi Percy š
Well done! !!
Thank you, it was exactly what I needed for a first clear and simple introduction
this is nice and really helpful
Nice intro! But how do you manage SystemD services in rootless containers within Molecule?
Does molecule works ok with mitogen? I know the connection is local to your docker container but as you may know ansible creates and kills the connection for each task, instead mitogen changes this behaviour to one single stable connection per each target. So when testing multiple tasks/hosts this might speed up the process
Can you update this Video the driver-name docker is not supported anymore.
Error: Invalid value for "–driver-name" / "-d": invalid choice: docker. (choose from delegated)
But awesome Video. I liked it very much!!
awesome and perfect tutorial nice work
Do you plan to update this tutorial? because the steps does not work anymore on the latest molecule version (molecule 3.1.5) š
Thanks for the great video! I would be interested to know how far you can push this? Would it be possible to test a shell script with it? I have one that calls local ansilbe playbooks.
Perfect. Thank you so much.
hello, thanks for this great video. Could you please fork and add geerlingguy centos8 and debian10 docker image for non root user ? thanks
Molecule doesn't work on python2.7 it required python3*..
Docker should installed and docker-py also required to run this right ??
I'm running Ansible on Amazon-linux2 and roles under it, I installed molecule using pip and docker-py as well. When I say molecule test it's giving me an error saying some apiversion error, can anyone pls help
I have a problem with molecule test…. Please help, thinks —
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
image: centos:7
name: instance
provisioner:
lint:
name: ansible-lint
name: ansible
scenario:
name: default
verifier:
lint:
name: flake8
name: testinfra
ERROR: Failed to pre-validate.
{'lint': ['must be of string type'], 'platforms': ['must be of list type']}
Hi Percy,hope you are doing great
Just wanted to know is that mitogen is a open source tools or do we have to pay for it
Super well explained! Thanks a lot!
This tutorial has been very helpful. Thanks you!
Hey Percy! I'm just now learning molecule myself, and I realized that since making this video, they've released Molecule 3! Some of the syntax and things are different, I would LOVE to see a video that shows how to get started in the new version. Thanks!
Nice
My CI/CD say thanks
wowww!! you are amazing!
well explained and I appreciate you breaking down the steps, helps demystify Molecule and give me a better gist and outline of what's happening
Hi, how to run an integration test with Molecule? let's say I have a role that setup database replication and I need one container run as a master DB before my molecule test run?.
I have following error running
molecule test
…..
TASK [Wait for instance(s) deletion to complete] *****************************
failed: [localhost] (item=None) => {"attempts": 1, "censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result", "changed": false}
fatal: [localhost]: FAILED! => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result", "changed": false}
….
Any idea?
Thank you.
thank for the content, however would like to know do you have a git repos?
Reedus instance… but seriously . Nice video
I seem to get the following FAILED error. Is there a way to stop this from happening?
TASK [Wait for instance(s) creation to complete] *****************************
Ā Ā FAILED – RETRYING: Wait for instance(s) creation to complete (300 retries left).
Ā Ā changed: [localhost] => (item=None)
Ā Ā changed: [localhost] => (item=None)
Ā Ā changed: [localhost]
This was awesome, very well explained! š Cheers mate
sir any videos like this for ansible test kitchen? how to write test cases for my roles using test kitchen .
The video is great, but I'm just not sure if I can forgive the absence of a night theme in VScode.
Hi Percy. What is the best place to include ansible script which are part of a git project? Meaning I have a code base whether its scripts of compiled code and I want to install this after building. So Project123 has my code. Where would I include Project1234-ansible.yml? Should that go into the Project123 repo or some other outside project?
This is great! Thanks for sharing. I look forward to seeing more Ansible content from you.
Iāve tried molecule but canāt figure out a way to use it for my job. Basically our software suite is automation of building a suite of virtual machines. We use VMware to create these vms. So I would need molecule to not create a docker image but instead run our build vm playbook. Do you know how this would work?
I found that setting up molecule outside of virtualenv is very buggy. When I use virtualenv, everything works as expected.
Very well done. Thanks.
Is there a recommended example for adopting existing roles into molecule?
How do I write tests if I have different tasks for different instances ? Just one testing file for all instances ? If yes, how to define the testings for each instance in the testing file ?
Excellent tutorial
Very nice