molecule python

Automated testing for Ansible roles

2 years after

Molecule


.. image:: https://badge.fury.io/py/molecule.svg :target: https://badge.fury.io/py/molecule :alt: PyPI Package

.. image:: https://readthedocs.org/projects/molecule/badge/?version=latest :target: https://molecule.readthedocs.io/en/latest/ :alt: Documentation Status

.. image:: https://img.shields.io/badge/license-MIT-brightgreen.svg :target: LICENSE :alt: Repository License

Molecule is designed to aid in the development and testing of Ansible_ roles including support for multiple instances, operating system distributions, virtualization providers and test frameworks.

It leverages Vagrant, Docker, and OpenStack to manage virtual machines/containers, with support for multiple Vagrant providers (currently VirtualBox, Parallels, VMware Fusion, and Libvirt). Molecule supports Serverspec, Testinfra, or Goss (beta) to run tests. Molecule uses an Ansible playbook (playbook.yml), to execute the role_ and its tests.

.. Test Kitchen: http://kitchen.ci .. playbook: https://docs.ansible.com/ansible/playbooks.html .. _role: http://docs.ansible.com/ansible/playbooks_roles.html

Ansible Support

  • 1.9.6 - Limited (Docker driver not-supported by Ansible)
  • 2.0.2.0 - Supported
  • 2.1.2.0 - Supported
  • 2.2.0.0 - Supported

Dependencies

Molecule relies on several outside packages and programs to function.

  • Ansible_

Verifier

  • Goss_
  • Serverspec_
  • Testinfra_ (default)

Driver

  • Docker_
  • Openstack_
  • Vagrant_ (default)

Provider

  • Libvirt_
  • Parallels_
  • VirtualBox_ (default)
  • VMware Fusion_

.. Ansible: https://docs.ansible.com .. Docker: https://www.docker.com .. Goss: https://github.com/aelsabbahy/goss .. Libvirt: http://libvirt.org .. OpenStack: https://www.openstack.org .. Parallels: http://www.parallels.com .. Serverspec: http://serverspec.org .. Testinfra: https://testinfra.readthedocs.io .. Vagrant: http://docs.vagrantup.com/v2 .. VirtualBox: https://www.virtualbox.org .. _VMware Fusion: http://www.vmware.com/products/fusion.html

Quick Start

.. important::

Ansible_ and the driver's python package require installation.

Install OS dependencies on CentOS 6/7

.. code-block:: bash

$ yum install -y epel-release $ yum install gcc python-devel openssl-devel libffi-devel

Install OS dependencies on Ubuntu 16.x

.. code-block:: bash

$ apt-get update $ apt-get install gcc python-pip python-vagrant libssl-dev libffi-dev

Install Molecule using pip:

.. code-block:: bash

$ pip install ansible $ pip install docker-py $ pip install molecule

Create a new role with the docker driver:

.. code-block:: bash

$ molecule init --role foo --driver docker --> Initializing role foo... Successfully initialized new role in /private/tmp/foo.

Or add Molecule to an existing role:

.. code-block:: bash

$ cd foo $ molecule init --driver docker --> Initializing molecule in current directory... Successfully initialized new role in /private/tmp/foo.

Update the role with needed functionality and tests. Now test it:

.. code-block:: bash

$ cd foo $ molecule test --> Destroying instances... --> Checking playbook's syntax...

playbook: playbook.yml --> Creating instances... Creating container foo with base image ubuntu:latest... Container created. --> Starting Ansible Run...

PLAY [all] *****

TASK [setup] *** ok: [foo]

PLAY RECAP ***** foo : ok=1 changed=0 unreachable=0 failed=0

--> Idempotence test in progress (can take a few minutes)... --> Starting Ansible Run... Idempotence test passed. --> Performing a 'Dry Run' of playbook...

PLAY [all] *****

TASK [setup] *** ok: [foo]

PLAY RECAP ***** foo : ok=1 changed=0 unreachable=0 failed=0

--> Executing ansible-lint... --> Executing flake8 on *.py files found in tests/... --> Executing testinfra tests found in tests/... ============================= test session starts ============================== platform darwin -- Python 2.7.12, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 rootdir: /private/tmp/foo, inifile: pytest.ini plugins: testinfra-1.4.4 collected 1 itemss

tests/test_default.py .

============================ pytest-warning summary ============================ WP1 None Modules are already imported so can not be re-written: testinfra ================= 1 passed, 1 pytest-warnings in 0.89 seconds ================== --> Destroying instances... Stopping container foo... Removed container foo.

Documentation

https://molecule.readthedocs.io/

License

MIT

The logo is licensed under the Creative Commons NoDerivatives 4.0 License_. If you have some other use in mind, contact us.

.. _Creative Commons NoDerivatives 4.0 License: https://creativecommons.org/licenses/by-nd/4.0/

Related Repositories

speck

speck

Browser-based WebGL molecule renderer with the goal of producing figures that ar ...

chemozart

chemozart

Web-based 3D molecule editor and visualizer with molecular mechanics calculators ...

imolecule

imolecule

An embeddable webGL molecule viewer and file format converter. ...

molecule-input

molecule-input

A Material Design text field ...

MolVS

MolVS

Molecule Validation and Standardization ...


Top Contributors

retr0h abrown-sg rgreinho dhutty kireledan bborysenko alop alvaroaleman signed8bit conorsch nmische 0xDEC0DE timgclark sebinjohn Holmser giovtorres milosgajdos83 pgporada srisakha oserde adamchainz charlieb00 cimarron-pistoncloud DavidWittman dbryant4 elliotweiser hectcastro lewg infothrill pporada-gl

Releases

-   1.17.3 zip tar
-   1.17.2 zip tar
-   1.17.1 zip tar
-   1.17 zip tar
-   1.16 zip tar
-   1.15 zip tar
-   1.14.1 zip tar
-   1.14 zip tar
-   1.13 zip tar
-   1.12.6 zip tar
-   1.12.5 zip tar
-   1.12.4 zip tar
-   1.12.3 zip tar
-   1.12.2 zip tar
-   1.12.1 zip tar
-   1.12 zip tar
-   1.11.5 zip tar
-   1.11.4 zip tar
-   1.11.3 zip tar
-   1.11.2 zip tar
-   1.11.1 zip tar
-   1.11 zip tar
-   1.10.3 zip tar
-   1.10.2 zip tar
-   1.10.1 zip tar
-   1.10 zip tar
-   1.9.1 zip tar
-   1.9.0 zip tar
-   1.8.4 zip tar
-   1.8.3 zip tar