Usage

Quick Start

Install Molecule using pip:

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

Create a new role:

$ molecule init role --role-name foo
--> Initializing new role foo...
Initialized role in /tmp/foo successfully.

Or Create a new scenario in an existing role:

$ cd foo
$ molecule init scenario --role-name foo --scenario-name new-scenario
--> Initializing new scenario new-scenario...
Initialized scenario in /tmp/foo/molecule/new-scenario successfully.
  1. Update the role with needed functionality and tests.
  2. Install the dependencies by following the instructions in INSTALL.rst included in the role’s scenario directory.
  3. Now test it.
$ cd foo
$ molecule test
--> Scenario: [default]
--> Provisioner: [ansible]
--> Playbook: [destroy.yml]

    PLAY [localhost] ***************************************************************

    TASK [setup] *******************************************************************
    ok: [localhost]

    TASK [Destroy molecule instance(s)] ********************************************
    ok: [localhost] => (item={'name': u'instance-1'})

    PLAY RECAP *********************************************************************
    localhost                  : ok=2    changed=0    unreachable=0    failed=0

--> Scenario: [default]
--> Dependency: [galaxy]
Skipping, missing the requirements file.
--> Scenario: [default]
--> Provisioner: [ansible]
--> Syntax Verification of Playbook: [playbook.yml]

    playbook: /Users/jodewey/git/molecule_2/test/scenarios/docker/foo/molecule/default/playbook.yml
--> Scenario: [default]
--> Provisioner: [ansible]
--> Playbook: [create.yml]

    PLAY [localhost] ***************************************************************

    TASK [setup] *******************************************************************
    ok: [localhost]

    TASK [Build an Ansible compatible image] ***************************************
    ok: [localhost]

    TASK [Create molecule instance(s)] *********************************************
    changed: [localhost] => (item={'name': u'instance-1'})

    PLAY RECAP *********************************************************************
    localhost                  : ok=3    changed=1    unreachable=0    failed=0

--> Scenario: [default]
--> Provisioner: [ansible]
--> Playbook: [playbook.yml]

    PLAY [all] *********************************************************************

    TASK [setup] *******************************************************************
    ok: [instance-1-default]

    PLAY RECAP *********************************************************************
    instance-1-default         : ok=1    changed=0    unreachable=0    failed=0

--> Scenario: [default]
--> Provisioner: [ansible]
--> Idempotence Verification of Playbook: [playbook.yml]
Idempotence completed successfully.
--> Scenario: [default]
--> Lint: [ansible-lint]
Lint completed successfully.
--> Scenario: [default]
--> Verifier: [testinfra]
--> Executing flake8 on files found in /Users/jodewey/git/molecule_2/test/scenarios/docker/foo/molecule/default/tests/...
--> Executing testinfra tests found in /Users/jodewey/git/molecule_2/test/scenarios/docker/foo/molecule/default/tests/...
    ============================= test session starts ==============================
    platform darwin -- Python 2.7.12, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
    rootdir: /Users/jodewey/git/molecule_2, inifile: pytest.ini
    plugins: testinfra-1.5.1, mock-1.5.0, helpers-namespace-2016.7.10, cov-2.4.0
collected 1 itemss

    tests/test_default.py .

    ============================ pytest-warning summary ============================
    WP1 None Module already imported so can not be re-written: testinfra
    ================= 1 passed, 1 pytest-warnings in 0.64 seconds ==================
Verifier completed successfully.
--> Scenario: [default]
--> Provisioner: [ansible]
--> Playbook: [destroy.yml]

    PLAY [localhost] ***************************************************************

    TASK [setup] *******************************************************************
    ok: [localhost]

    TASK [Destroy molecule instance(s)] ********************************************
    changed: [localhost] => (item={'name': u'instance-1'})

    PLAY RECAP *********************************************************************
    localhost                  : ok=2    changed=1    unreachable=0    failed=0

Check

class molecule.command.check.Check

Target the default scenario:

>>> molecule check

Targeting a specific scenario:

>>> molecule check --scenario-name foo

Executing with debug:

>>> molecule --debug check

Converge

Converge will execute the sequences necessary to converge the instances.

class molecule.command.converge.Converge

Target the default scenario:

>>> molecule converge

Targeting a specific scenario:

>>> molecule converge --scenario-name foo

Executing with debug:

>>> molecule --debug converge

Create

class molecule.command.create.Create

Target the default scenario:

>>> molecule create

Targeting a specific scenario:

>>> molecule create --scenario-name foo

Targeting a specific driver:

>>> molecule converge --driver-name foo

Executing with debug:

>>> molecule --debug create

Dependency

class molecule.command.dependency.Dependency

Target the default scenario:

>>> molecule dependency

Targeting a specific scenario:

>>> molecule dependency --scenario-name foo

Executing with debug:

>>> molecule --debug dependency

Destroy

class molecule.command.destroy.Destroy

Target the default scenario:

>>> molecule destroy

Targeting a specific scenario:

>>> molecule destroy --scenario-name foo

Targeting a specific driver:

>>> molecule converge --driver-name foo

Executing with debug:

>>> molecule --debug destroy

Destruct

class molecule.command.destruct.Destruct

This is a destructive action and not enabled by default. See the provisioners documentation for further details.

Target the default scenario:

>>> molecule destruct

Targeting a specific scenario:

>>> molecule destruct --scenario-name foo

Executing with debug:

>>> molecule --debug destruct

Idempotence

class molecule.command.idempotence.Idempotence

Target the default scenario:

>>> molecule idempotence

Targeting a specific scenario:

>>> molecule idempotence --scenario-name foo

Executing with debug:

>>> molecule --debug idempotence

Init

init._init_new_role()

Initialize a new role:

>>> molecule init role --role-name foo
init._init_new_scenario()

Initialize a new scenario:

>>> molecule init scenario --scenario-name default --role-name foo
init._init_template()

Initialize a new role from a Cookiecutter URL:

>>> molecule init template --url https://example.com/user/cookiecutter-repo

Lint

class molecule.command.lint.Lint

Target the default scenario:

>>> molecule lint

Targeting a specific scenario:

>>> molecule lint --scenario-name foo

Executing with debug:

>>> molecule --debug lint

List

class molecule.command.list.List

Target all scenarios:

>>> molecule list

Targeting a specific scenario:

>>> molecule list --scenario-name foo

Machine readable output:

>>> molecule list --format plain
>>> molecule list --format yaml

Executing with debug:

>>> molecule --debug list

Login

class molecule.command.login.Login

Targeting the only running host:

>>> molecule login

Targeting a specific running host:

>>> molecule login --host hostname

Targeting a specific running host and scenario:

>>> molecule login --host hostname --scenario-name foo

Executing with debug:

>>> molecule --debug login

Syntax

class molecule.command.syntax.Syntax

Target the default scenario:

>>> molecule syntax

Targeting a specific scenario:

>>> molecule syntax --scenario-name foo

Executing with debug:

>>> molecule --debug syntax

Test

Test will execute the sequences necessary to test the instances.

class molecule.command.test.Test

Target all scenarios:

>>> molecule test

Targeting a specific scenario:

>>> molecule test --scenario-name foo

Targeting a specific driver:

>>> molecule converge --driver-name foo

Executing with debug:

>>> molecule --debug test

Verify

class molecule.command.verify.Verify

Target the default scenario:

>>> molecule verify

Targeting a specific scenario:

>>> molecule verify --scenario-name foo

Executing with debug:

>>> molecule --debug verify