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 to manage virtual machines,
with support for multiple Vagrant providers (currently VirtualBox and OpenStack).
Molecule supports Serverspec or Testinfra to run tests. Molecule uses an Ansible
playbook (playbook.yml
), to execute the role and its tests.
Install molecule using pip:
$ pip install molecule
Create a new role:
$ molecule init foo
Successfully initialized new role in ./foo/
Update the role with needed functionality and tests. Now test it:
$ cd foo
$ molecule test
==> vagrant-01: VM not created. Moving on...
==> vagrant-01: VM not created. Moving on...
Bringing machine 'vagrant-01' up with 'virtualbox' provider...
==> vagrant-01: Importing base box 'hashicorp/precise64'...
...
==> vagrant-01: Machine not provisioned because `--no-provision` is specified.
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [vagrant-01]
TASK: [foo | install curl] ****************************************************
changed: [vagrant-01]
PLAY RECAP ********************************************************************
vagrant-01 : ok=2 changed=1 unreachable=0 failed=0
Idempotence test in progress... OKAY
Inspecting 2 files
..
2 files inspected, no offenses detected
/Users/jodewey/.rvm/rubies/ruby-2.2.0/bin/ruby -I/Users/jodewey/.rvm/gems/ruby-2.2.0/gems/rspec-support-3.3.0/lib:/Users/jodewey/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.3.2/lib /Users/jodewey/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.3.2/exe/rspec --pattern spec/\*_spec.rb,spec/vagrant-01/\*_spec.rb,spec/hosts/vagrant-01/\*_spec.rb,spec/group_1/\*_spec.rb,spec/groups/group_1/\*_spec.rb,spec/group_2/\*_spec.rb,spec/groups/group_2/\*_spec.rb
Package Installation
Package "curl"
should be installed
Finished in 0.40244 seconds (files took 0.90459 seconds to load)
1 example, 0 failures
==> vagrant-01: Attempting graceful shutdown of VM...
==> vagrant-01: Destroying VM and associated drives...
http://molecule.readthedocs.org/en/latest/
MIT
The logo is licensed under the Creative Commons NoDerivatives 4.0 License. If you have some other use in mind, contact us.