Stumbled upon Link to heading

As I am currently looking for a new gig, I have some extra time. I never took the time to look into the Kelsey Hightower’s Kubernetes the Hard Way. There are many different ways to bootstrap a Kubernetes cluster. Kelsey’s open-source guide goes through how to bootstrap cluster without the use of installers or scripts. This approach gives us a deeper understanding of the details of Kubernetes. I am always eager and curious about how moving parts are working together, and “lazy” as good developers are I did automate some of the steps with Ansible. While I was re-using previously written roles, I’ve found out that Molecule test verify sequence is not working.

The Molecule is a project that is designed to aid in the development and testing of Ansible roles. Molecule supports only the latest two major versions on Ansible, and most of the roles I’ve written were in the time Ansible version 2.6.x was the latest. When using Ansible with Molecule, you’ll be encouraged to write roles that are well-written, easily understood and maintained.

So what changed? Link to heading

Since Molecule v3 Testinfra is no longer default test verifier, if you still would like to use it, you must add it as a pip dependency as is no longer installed by default. Goss verifier was also removed, and Ansible is now the default test verifier.

Why the change? Link to heading

The current user experience (writing tests in Python with powerful pytest test engine) is inconsistent with the Ansible Engine and Ansible Galaxy. They both promise the ability to keep using YAML. “native” way of doing testing, so this should come first as this will also improve the experience for new Ansible users.

What about us who were used to write tests in Python. Should we switch to writing tests in Ansible? Link to heading

Absolutely. On first glance, writing tests in Ansible seems a little odd. But you probably already had some tasks in your playbooks which did some validation—for example, confirming that the service is responding with status code 200.

# Simple example
- name: Check healt of service
  uri:
    url: "http://localhost/health"
    status_code: 200
  register: register_health
  until: register_health.status == 200
  retries: 10
  delay: 10

Registering variables and using set_facts and assert modules will prove useful for testing.

For further ideas on how to test with Ansible reference the documentation and Ansible source code of test verifying:

Example Link to heading

Let’s look at a simple example. Let’s say we would like to use Molecule to test if some set of packages were installed within the role.

What do you think?

And remember, contributions earn you karma. 😜