Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/samdoran/container-alpine-ansible

Container for testing Ansible roles
https://github.com/samdoran/container-alpine-ansible

Last synced: 3 days ago
JSON representation

Container for testing Ansible roles

Awesome Lists containing this project

README

        

# Alpine Ansible Test Image #
[![Container Repository on Quay](https://quay.io/repository/samdoran/alpine-ansible/status "Container Repository on Quay")](https://quay.io/repository/samdoran/alpine-ansible)

This is a container for testing Ansible roles with [Molecule](https://molecule.readthedocs.io/en/latest/). It includes the latest version of Ansible available on this platform and is rebuilt regularly. It can also be used if you need to run Ansible on a specific operating system.

Note that Molecule does not use the Ansible version installed in the container when running tests.

## Build ##

To build your own version of this container, run:

podman build -t alpine-ansible -f Containerfile .

## Testing a role using Molecule ##

If you don't already have a role repository, you can initialize one using this [cookiecutter template](https://github.com/samdoran/cookiecutter-ansible-role).

`molecule init template --url https://github.com/samdoran/cookiecutter-ansible-role`

Then run `molecule test` to run the full test suite against the role.

Run `molecule converge` to run the role against the test container but leave it running. This allows you to connect to the container using `molecule login` or just test running your role multiple times against an existing container.

If you already have a role being testing using Molecule, add this to the `platforms` section of your `molecule.yml` to use this image:

```yaml
platforms:
- name: role-test
image: "samdoran/${MOLECULE_DISTRIBUTION:-alpine}-ansible:latest"
command: ${MOLECULE_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: yes
pre_build_image: yes
```

The important parts are `pre_build_image: yes` and the `image` name. Molecule allows you to use environment variables in the configuration file, which is very handy. This allows you to easily change the container that molecule uses for tests (among other things) simply by changing the enivorment variable.

```
env MOLECULE_DISTRIBUTION=debian10 molecule test
```