Skip to main content

Molecule Hetzner Cloud Plugin :: run molecule tests with hetzner cloud

Project description

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.

Support

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.

Install

$ pip install molecule-hetznercloud

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

Upgrade

Please see the CHANGELOG.md for migration guides.

$ pip install --upgrade molecule-hetznercloud

Usage

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.

---
dependency:
  name: galaxy
driver:
  name: hetznercloud
platforms:
  - name: instance
    server_type: cx11
    image: debian-10
provisioner:
  name: ansible
verifier:
  name: ansible

Please see docs.hetzner.cloud 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.

platforms:
  - name: instance
    server_type: cx11
    image: debian-10
    volumes:
      - 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:

platforms:
  - name: instance1
    server_type: cx11
    image: debian-10
    networks:
      test-network:
        ip_range: 10.10.0.0/16
        subnet:
          ip: 10.10.10.1/24
          type: cloud
          network_zone: eu-central
      test-network-2:
        ip_range: 10.20.0.0/16
        subnet:
          ip: 10.20.10.1/24
  - name: instance2
    server_type: cx11
    image: debian-10
    networks:
      test-network:
        subnet:
          ip: 10.10.10.2/24

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.

Mirroring

Issues will be responded to on both issue trackers.

Change log

See CHANGELOG.md.

Molecule Documentation

https://molecule.readthedocs.io

Contact

  • Ping @decentral1se on the #ansible-molecule channel on Libera.

License

The LGPLv3 license.

Testing

This is all done on our drone.autonomic.zone setup.

Unit

$ pip install tox
$ tox -v

Integration

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

molecule-hetznercloud-1.3.0.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

molecule_hetznercloud-1.3.0-py2.py3-none-any.whl (33.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file molecule-hetznercloud-1.3.0.tar.gz.

File metadata

  • Download URL: molecule-hetznercloud-1.3.0.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for molecule-hetznercloud-1.3.0.tar.gz
Algorithm Hash digest
SHA256 8691ec6a5c520ff11f94944a97b9fb3fdbd5c21cb09ee275d17e806af02624f5
MD5 29a862e5f03b277d6d6196dc814b1e8f
BLAKE2b-256 e7d20f75964d3f2fa55a544f9ced97a8e97647d86ed1d7f0b94ae190b7a02ca2

See more details on using hashes here.

File details

Details for the file molecule_hetznercloud-1.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: molecule_hetznercloud-1.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 33.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for molecule_hetznercloud-1.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 747d335d8878ab349b0f1ad359710b5bbc4548a17d54ca6277331bdd6cb801d1
MD5 4d184cc31fc1eb43d347181582d8601f
BLAKE2b-256 a86c7a1638bf08eb84a8159023b8e971e0cb9ace5814fc272d8db5ef306aadf2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page