Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robertdebock/molecule-action
Test Ansible roles using Molecule
https://github.com/robertdebock/molecule-action
Last synced: 6 days ago
JSON representation
Test Ansible roles using Molecule
- Host: GitHub
- URL: https://github.com/robertdebock/molecule-action
- Owner: robertdebock
- License: apache-2.0
- Created: 2019-12-19T16:16:12.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-08T13:58:48.000Z (10 months ago)
- Last Synced: 2024-10-06T05:17:25.466Z (about 1 month ago)
- Homepage: https://robertdebock.nl/
- Size: 55.7 KB
- Stars: 55
- Watchers: 5
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-actions - Test Ansible roles with Molecule
- fucking-awesome-actions - Test Ansible roles with Molecule
- awesome-workflows - Test Ansible roles with Molecule
README
# Molecule action
A GitHub action to test your [Ansible](https://www.ansible.com/) role using [Molecule](https://molecule.readthedocs.io/).
## Requirements
This action can work with Molecule scenarios that use the [`docker`](https://molecule.readthedocs.io/configuration) driver.
This action expects the following (default Ansible role) structure:
```
.
├── defaults
│ └── main.yml
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── molecule
│ └── default
│ ├── molecule.yml
│ ├── playbook.yml
│ └── prepare.yml
├── requirements.yml
├── tasks
│ └── main.yml
├── tox.ini # OPTIONAL
└── vars
└── main.yml
```If you are missing the `molecule` directory, please have a look at this [skeleton role](https://github.com/robertdebock/ansible-role-skeleton) or one of the many examples listed on [my website](https://robertdebock.nl/).
When `tox.ini` is found, [tox](https://tox.readthedocs.io/en/latest/) is used to test the role. Tox will install all dependecies found in `tox.ini` itself, meaning `tox.ini` determines the version of [molecule](https://molecule.readthedocs.io/en/latest/) that is used.
## Inputs
### `namespace`
The Docker Hub namespace where the image is in. Default `"robertdebock"`.
### `image`
The image you want to run on. Default `"fedora"`.
### `tag`
The tag of the container image to use. Default `"latest"`.
### `options`
The [options to pass to `tox`](https://tox.readthedocs.io/en/latest/config.html#tox). For example `parallel`. Default `""`. (empty)
### `command`
The molecule command to use. For example `create`. Default `"test"`.
### `scenario`
The molecule scenario to run. Default `"default"`
## Example usage
Here is a default configuration that tests your role on `namespace: robertdebock`, `image: fedora`, `tag: latest`.
```yaml
---
on:
- pushjobs:
build:
runs-on: ubuntu-20.04
steps:
- name: checkout
uses: actions/checkout@v3
with:
path: "${{ github.repository }}"
- name: molecule
uses: robertdebock/[email protected]
```> NOTE: the `checkout` action needs to place the file in `${{ github.repository }}` in order for Molecule to find your role.
If you want to test your role against multiple distributions, you can use this pattern:
```yaml
---
name: CIon:
- pushjobs:
lint:
runs-on: ubuntu-20.04
steps:
- name: checkout
uses: actions/checkout@v3
with:
path: "${{ github.repository }}"
- name: molecule
uses: robertdebock/[email protected]
with:
command: lint
test:
needs:
- lint
runs-on: ubuntu-20.04
strategy:
matrix:
image:
- alpine
- amazonlinux
- debian
- centos
- fedora
- opensuse
- ubuntu
steps:
- name: checkout
uses: actions/checkout@v3
with:
path: "${{ github.repository }}"
- name: molecule
uses: robertdebock/[email protected]
with:
image: "${{ matrix.image }}"
options: parallel
scenario: my_specific_scenario
```## Debugging
You can enable Molecule debugging by using this pattern:
```yaml
# Stuff omitted.
- name: molecule
uses: robertdebock/[email protected]
with:
image: ${{ matrix.config.image }}
tag: ${{ matrix.config.tag }}
command: "--debug test"
```