Skip to content

Instantly share code, notes, and snippets.

@dragolabs
Last active October 4, 2021 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dragolabs/b9cfcdffd8348c5985a80fbdf07b33e4 to your computer and use it in GitHub Desktop.
Save dragolabs/b9cfcdffd8348c5985a80fbdf07b33e4 to your computer and use it in GitHub Desktop.

Ansible role with testing

Install ansible and tools

pipx install --include-deps yamllint
pipx install --include-deps ansible
pipx install --include-deps "ansible-lint[community,yamllint]"
pipx install --include-deps "molecule[docker]"
pipx inject --include-apps ansible ansible-lint
pipx inject --include-apps ansible molecule
pipx inject ansible docker
pipx inject ansible python-vagrant
pipx inject ansible netaddr
pipx inject ansible molecule-docker
pipx inject ansible molecule-podman
pipx inject ansible molecule-vagrant

Create role with molecule

molecule init role role_name --driver-name docker

Prepare molecule config

This is molecule/default/molecule.yml

---
dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: instance
    image: geerlingguy/docker-ubuntu2004-ansible
    pre_build_image: true
provisioner:
  name: ansible
verifier:
  name: ansible

Make some stuff in role

Don't forget to set properly values in meta/main.yml!

Run test

molecule test

Useful links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment