A couple of months ago I was going some work on one of my Ansible roles when I learned that Molecule had undergone a pretty significant upgrade. Rather than try to figure out how to fix it then, I just pinned molecule to version 2. This week I decided to circle back and upgrade my roles to Molecule 3. It ended up being pretty straight forward, thanks to this gist from Jeff Geerling. Rather than just blindly running a script, I stepped through it and made the updates manually and documented them.

The first step was to update my TravisCI build yaml to include additional python modules that are no longer requirements for Molecule including yamllint ansible-lint and testinfra.

- pip install molecule docker yamllint ansible-lint testinfra

The next step was to update my original molecule.yml file.

---
# Molecule 2 Configuration
dependency:
  name: galaxy
driver:
  name: docker
lint:
  name: yamllint
  options:
    config-file: molecule/default/yamllint.yml
platforms:
  - name: ubuntu-18.04
    image: austincloud/molecule-ubuntu-18.04
    privileged: True
    command: /sbin/init
  - name: amazonlinux
    image: austincloud/molecule-amazonlinux-1
    privileged: True
    command: /sbin/init
provisioner:
  name: ansible
  lint:
    name: ansible-lint
scenario:
  name: default
verifier:
  name: testinfra
  lint:
    name: flake8

I replaced the lint line:

lint:
  name: yamllint
  options:
    config-file: molecule/default/yamllint.yml

with

lint: |
  set -e
  yamllint .
  ansible-lint

Next I removed the scenario: entry and the lint section from provisioner: leaving me with a configuration file that will work in Molecule 3.

Finally, I updated the verifier: section by removing the lint section and adding the directory: section with the path to my testinfra scripts.

---
# Molecule 3 Configuration
dependency:
  name: galaxy
driver:
  name: docker
lint: |
  set -e
  yamllint .
  ansible-lint
platforms:
  - name: ubuntu-18.04
    image: austincloud/molecule-ubuntu-18.04
    privileged: True
    command: /sbin/init
  - name: amazonlinux
    image: austincloud/molecule-amazonlinux-1
    privileged: True
    command: /sbin/init
provisioner:
  name: ansible
verifier:
  name: testinfra
  directory: ./tests

Finally, I renamed the playbook file to converge to avoid deprecation warnings.

mv playbook.yml converge.yml

That was it. I had budgeted a week to upgrade all my roles, figuring I was going to need a few days to dig a little deeper into Molecule 3, but I ended up getting them all updated in an afternoon.