Test a Million Supported Systems with Molecule + GitHub Actions Matrix
Tags: actionshackathon, ansible, molecule
Published: 2020-08-13 23:46:12

[Instructions]: # (To submit to the GitHub Actions x DEV Hackathon, please fill out all sections.)

From a comment on the announcement article:

> For this contest, you'll only be able to submit projects that you started after this announcement post was published.

Well, I guess I am disqualified. But, leaving this post up as a resource for anyone that may like it.

### My Workflow
[Note]: # (Make sure to include the name of your GitHub Action and share where it's being used!)

I am a big fan of [Tailscale](https://tailscale.com/) for a [Wireguard](https://www.wireguard.com/) VPN mesh. Some months ago, someone [requested that Tailscale support](https://github.com/tailscale/tailscale/issues/270) an [Ansible Galaxy]() role to set up a Tailscale node. I saw the `help wanted` tag and knew what I must do.

However, Tailscale supports a large number of operating systems, and I wanted my Tailscale Ansible role to support everything that Tailscale supports. I needed a CI workflow that would test all those systems in parallel whenever I created a new PR.

I still have a few operating systems to add support for (dreading Windows and OSX for the CI difficulties they present), but I currently run tests against 10 operating systems in parallel using a GitHub Action workflow to spawn dynamic Action jobs that each run Molecule against a single system. This leverages a [GitHub Action matrix](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix).

### Submission Category: 

[Note]: # (Maintainer Must-Haves, DIY Deployments, Interesting IoT, Phone Friendly, or Wacky Wildcards)

Maintainer Must-Haves


### Yaml File or Link to Code

[Note]: # (Our markdown editor supports pretty embeds. Try this syntax: `{% github link_to_your_repo %}` to share a GitHub repository)

{% github artis3n/ansible-role-tailscale %}

The Ansible role can be found on Ansible Galaxy [here](https://galaxy.ansible.com/artis3n/tailscale).

The key for this GitHub Action matrix workflow to work is the following setup in my `molecule.yml` file:

```yml
platforms:
  - name: instance
    image: ${MOLECULE_DISTRO:-geerlingguy/docker-centos7-ansible:latest}
```

From there, I can set up which systems to run Molecule against with a matrix:

```yml
jobs:
  molecule:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        distros:
          - geerlingguy/docker-centos7-ansible:latest
          - geerlingguy/docker-centos8-ansible:latest
          - geerlingguy/docker-amazonlinux2-ansible:latest
          - geerlingguy/docker-ubuntu2004-ansible:latest
          - geerlingguy/docker-ubuntu1804-ansible:latest
          - geerlingguy/docker-ubuntu1604-ansible:latest
          - geerlingguy/docker-debian10-ansible:latest
          - geerlingguy/docker-debian9-ansible:latest
          - geerlingguy/docker-fedora31-ansible:latest
          - artis3n/docker-arch-ansible:latest
      fail-fast: false

    steps:
```

**Important!** - You don't want to forget `fail-fast: false`.
This stops the action workflow from stopping whenever a single job fails. We want each spawned job to run in isolation from the others, so we can independently see which systems are good and which have issues.

Then, we just need a single job definition that uses the `distro` matrix variable. GitHub Actions will automatically spawn a job for each item in the `matrix`.

```yml
- name: Molecule
        run: echo "${{ secrets.VAULT_PASS }}" > /home/runner/work/_temp/.vault-ci-pass && ANSIBLE_VAULT_PASSWORD_FILE=/home/runner/work/_temp/.vault-ci-pass pipenv run molecule test
        env:
          MOLECULE_DISTRO: "${{ matrix.distros }}"
```

This spawns a job for each matrix distribution:

![Actions workflow 10 spawned jobs](https://dev-to-uploads.s3.amazonaws.com/i/pudi5phhoo9rrko1b40u.png)

### Additional Resources / Info

[Note]: # (Be sure to link to any open source projects that are using your workflow!)

[Note]: # (Be sure to include the DEV usernames of your collaborators, if any. )

[Reminder]: # (Submissions are due on September 12th (11:59 PM PDT) and winners will be announced on September 23!)