not a tutorial, more of a tricks session
Based on molecule v3.0.2
Manual testing does not pay well!
Molecule provisions virtualized test hosts, run commands on them and assert the success.
pip3 install 'molecule[docker]' molecule-azure
# most drivers are now plugins and with their own packages
# docker driver is part of core
$ molecule --version
molecule 3.0.3.dev41+gbe117525
ansible==2.9.6 python==3.7
$ molecule drivers
name
---------
azure # <-- this is here because we installed molecule-azure
delegated
docker
podman

Tools used to assert success of your test
Default test sequence includes:
$ molecule matrix test
--> Test matrix
└── default # <-- this is the name of the scenario
├── dependency
├── lint
├── cleanup
├── destroy
├── syntax
├── create
├── prepare # bring host to testable status
├── converge # <-- only one required
├── idempotence
├── side_effect
├── verify # asserts best location
├── cleanup
└── destroy

create and destroy affect the created stateconverge and cleanup affect the converged state--destroy=never$ tree # from inside a role directory
├── README.md
├── defaults
│ └── main.yml
├── files
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── molecule
│ └── default # scenario name
│ ├── converge.yml # should contain at least "include_role: foo"
│ ├── molecule.yml # <-- required
│ └── verify.yml
├── tasks
│ └── main.yml
└── vars
└── main.yml
molecule.yml files~/.config/molecule/config.yml - user level{REPO}/.config/molecule/config.yml - repo level (recommended)molecule.yml will override values from config.yml# .config/molecule/config.ym
driver:
name: delegated # <-- now default driver will be delegated
lint: ansible-lint -v
# molecule.yml
driver:
name: docker
# what is effectively loaded
driver:
name: docker
lint: ansible-lint -v
Hint: Use config.yml to follow DRY principle