← 返回命令列表

Linux command

molecule 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Initialize a test scenario

molecule init scenario

Run full test sequence

molecule test

Create test instances

molecule create

Run playbook against instances

molecule converge

Verify instance state

molecule verify

Login to instance

molecule login

Destroy test instances

molecule destroy

说明

Molecule is a testing framework for Ansible roles. It creates test instances, runs playbooks against them, verifies results, and cleans up - enabling test-driven infrastructure development. A scenario defines how to test a role: which driver creates instances, which playbooks run, and which verifier checks results. Default scenarios use Docker but Podman, Vagrant, and cloud providers are supported. The test sequence runs: lint, cleanup, destroy, dependency, syntax, create, prepare, converge, idempotence, verify, cleanup, destroy. Individual stages can run separately during development. Verification typically uses Ansible's assert module or Testinfra for Python-based tests. Tests check that the role achieved the desired state: files exist, services run, configurations are correct. Idempotence testing runs the playbook twice, failing if changes occur on the second run. This ensures roles are properly idempotent. CI integration works with GitHub Actions, GitLab CI, and other platforms. The test command returns appropriate exit codes for automation.

参数

init role _NAME_
Create new Ansible role with Molecule.
init scenario
Add scenario to existing role.
test
Run full test sequence.
create
Create instances.
converge
Run playbook.
verify
Run verification tests.
destroy
Destroy instances.
login _HOST_
Login to instance shell.
list
List instances and status.
lint
Run linters.
cleanup
Run cleanup playbook.
-s _NAME_, --scenario-name _NAME_
Target scenario.
-d _NAME_, --driver-name _NAME_
Driver: docker, podman, delegated, vagrant.
--all
Run against all scenarios.
--parallel
Run scenarios in parallel.
--destroy _WHEN_
When to destroy: always, never, passing.

FAQ

What is the molecule command used for?

Molecule is a testing framework for Ansible roles. It creates test instances, runs playbooks against them, verifies results, and cleans up - enabling test-driven infrastructure development. A scenario defines how to test a role: which driver creates instances, which playbooks run, and which verifier checks results. Default scenarios use Docker but Podman, Vagrant, and cloud providers are supported. The test sequence runs: lint, cleanup, destroy, dependency, syntax, create, prepare, converge, idempotence, verify, cleanup, destroy. Individual stages can run separately during development. Verification typically uses Ansible's assert module or Testinfra for Python-based tests. Tests check that the role achieved the desired state: files exist, services run, configurations are correct. Idempotence testing runs the playbook twice, failing if changes occur on the second run. This ensures roles are properly idempotent. CI integration works with GitHub Actions, GitLab CI, and other platforms. The test command returns appropriate exit codes for automation.

How do I run a basic molecule example?

Run `molecule init scenario` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does init role _NAME_ do in molecule?

Create new Ansible role with Molecule.