Mastering Molecule

Controlling verbosity

Few things you may need to master quickly while working with molecule scenarios: how to control verbosity of different actions.

# disable nologs

# disable destroy

# debug mode (same as --debug) -- very verbose

# change ansible own verbosity

Passing Ansible arguments

In the end, molecule will call Ansible for testing your code but this does not mean that you cannot add your own options. You just need to use positional arguments for achieve that:

molecule test -- --tags foo
# this this call:
ansible-playbook ... --tags foo

Also you can use my favourite way of passing custom configuration by defining ANSIBLE_ prefixed environment variables, which will be recognized by Ansible.

Skipping tasks only during testing

Sometimes there are role tasks that you cannot or don’t want to run during functional testing. There are two magic ansible tags that you can use to mark these: notest and molecule-notest. Keep in mind that you can also use them on blocks or even at playbook level.