Rapidly Build & Test Ansible Roles with Molecule + Docker


    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


    ✅ 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/


    ✅ 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


    Previous articleAutomating the deployment of SAP HANA database with Ansible Tower
    Next articleAutomation with Ansible Playbooks | Inventory file with Groups and Group of Groups


    1. I have a problem with molecule test…. Please help, thinks —


      name: galaxy


      name: docker


      name: yamllint


      image: centos:7

      name: instance



      name: ansible-lint

      name: ansible


      name: default



      name: flake8

      name: testinfra

      ERROR: Failed to pre-validate.

      {'lint': ['must be of string type'], 'platforms': ['must be of list type']}

    2. 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!

    3. 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.

    4. 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]

    5. 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?