Molecule Hetzner Cloud driver plugin
Go to file
decentral1se 0dd5032df9
continuous-integration/drone/push Build is passing Details
Mark release, point to change log
2021-09-13 11:31:20 +02:00
.github Add missing header 2020-04-26 00:57:33 +02:00
integration Disable volume testing for now 2021-06-02 11:04:23 +02:00
molecule_hetznercloud Remove deprecated molecule cache (#35) 2021-09-02 12:49:08 +01:00
.drone.yml Add possibility to create networks 2021-06-02 10:51:44 +02:00
.envrc.sample Fixup envrc.sample with missing env var 2020-04-24 14:38:24 +02:00
.gitignore Testing configuration cleanup 2020-04-24 10:45:20 +01:00
.pre-commit-config.yaml Fix linters 2020-04-24 14:19:38 +02:00
.yamllint.yml Remove Molecule project cruft 2020-04-24 14:41:40 +02:00 Mark release, point to change log 2021-09-13 11:31:20 +02:00
LICENSE Relicense to LGPL 2020-04-24 12:22:29 +02:00
Makefile Remove cruft and shorten dir name 2020-04-24 15:09:25 +02:00 Add that dep 2021-06-02 13:21:37 +02:00
pyproject.toml Shape up package configuration and update deps 2020-04-24 13:24:38 +02:00
pytest.ini Ignore those warnings 2019-11-16 08:05:55 +07:00
setup.cfg Remove deprecated molecule cache (#35) 2021-09-02 12:49:08 +01:00 Testing configuration cleanup 2020-04-24 10:45:20 +01:00
tox.ini Py39, Molecule 3.2.1 and dep tree upgrade 2021-01-06 11:49:48 +01:00

Molecule Hetzner Cloud Plugin

Drone CI-CD PyPI Package Repository License

A Hetzner Cloud plugin for Molecule.

This plugin allows you to do molecule init role myrolename -d hetznercloud and have Molecule provision on-demand Hetzner Cloud VPSes of your choice for your integration testing. New VPSes will be automagically created and provisioned on each molecule test run, SSH keys are generated and managed internally and all resources are cleaned up regardless of whether the role under test succeeds or fails.


If you use this plugin in a commercial setting or you find it personally useful, please support my maintenance work financially through my Liberapay profile or through my Github Sponsor profile. I do not receive any financial support from RedHat or Hetzner Cloud for this work.


$ pip install molecule-hetznercloud

If you're looking for a container approach, see ansible-community/toolset.


Please see the for migration guides.

$ pip install --upgrade molecule-hetznercloud


You need to expose a HCLOUD_TOKEN environment variable in your environment.

Find out more about how to get one of those over here.

$ export HCLOUD_TOKEN=mycoolapitoken

Then create a role using the driver plugin.

$ molecule init role myrolename -d hetznercloud

Your myrolename/molecule/default/molecule.yml should then look like the following.

  name: galaxy
  name: hetznercloud
  - name: instance
    server_type: cx11
    image: debian-10
  name: ansible
  name: ansible

Please see for information regarding images and server types.

Then just run the role.

$ cd myrolename && molecule test

To ease initial debugging for getting things started, also expose the following environment variables.

$ export MOLECULE_NO_LOG=False  # not so verbose, helpful
$ export MOLECULE_DEBUG=True  # very verbose, last ditch effort

Volume Handling

WARNING: this feature appears to be broke. See #24 for more

It is possible to have the driver manage volumes during the test run. You can add the following stanza to your Molecule configuration to have Molecule create this volume for the managed VPS. This volume will be cleaned up after use.

  - name: instance
    server_type: cx11
    image: debian-10
      - name: "molecule-hetznercloud-volume-1-${INSTANCE_UUID}"
        location: /foo/bar
      - name: "molecule-hetznercloud-volume-2-${INSTANCE_UUID}"
        size: 20

Supported keys are:

  • name (required): name of volume
  • size (optional, default: 10GB): size of volume
  • location (optional, default: omitted): path for volume

Network Creation

This Driver is able to generate networks and subnetworks during the test run. This can be useful for cluster tests. You can create networks with the following snippet:

  - name: instance1
    server_type: cx11
    image: debian-10
          type: cloud
          network_zone: eu-central
  - name: instance2
    server_type: cx11
    image: debian-10

The networks ip_range is only important for creating. If you have multiple hosts, it is okay to only define ip_range once. The supported keys are:

  • networks

    • ip_range (required): ip range of network (usually /16)
  • subnet

    • ip (required): ip that should be assigned to host (also generates subnetwork) - prefix mandatory
    • type (optional, default: cloud): type of subnetwork
    • network_zone (optional, default: eu-central): network zone of subnetwork

Only use molecule.yml for configuration

It is being worked on that it is possible to remove all the files except the molecule.yml scenario file in your scenario directory. This is useful when you only require this plugin to do the default behaviour each time. It is also useful to reduce maintenance effort for migration of configurations. This plugin currently embeds the create.yml and destroy.yml playbooks. All other playbooks (e.g. prepare, cleanup) can be created as needed and Molecule will pick them up and run them. Embedding the converge.yml awaits this feature request.


Issues will be responded to on both issue trackers.

Change log


Molecule Documentation



The LGPLv3 license.


This is all done on our setup.


$ pip install tox
$ tox -v


git clone
cd molecule-hetznercloud
python3 -m venv .venv && source .venv/bin/activate
pip install -e . "ansible<4" netaddr
export INSTANCE_UUID=$(openssl rand -hex 5)
cd integration && molecule test