---
title: "Example of Ansible Molecule in OpenStack - Fairbanks"
description: "Molecule provides support for testing with multiple instances, operating systems and distributions, test frameworks and scenarios."
url: "https://fairbanks-upgrade.ubo-dev.nl/ansible-molecule-openstack-examples/"
language: "en"
---

Blog

# Example of Ansible Molecule in OpenStack

Technology

August 15, 2023

Author: Elvira Dautović

Share this post

Molecule is a testing framework for Ansible roles that allows you to define and run tests against your roles in various scenarios. Molecule provides support for testing with multiple instances, operating systems and distributions, virtualization providers, test frameworks and testing scenarios. Molecule encourages an approach that results in consistently developed roles that are well-written, easily understood and maintained. 

By coupling Ansible Molecule with the potential of OpenStack, you can evaluate your Ansible roles in a cloud environment. This strategic testing approach bolsters your confidence in the functionality and reliability of your roles, paving the way for seamless deployments and enhanced system stability. Please note that software and tools continuously evolved since, so I recommend checking the latest documentation for any changes or updates. 

Here’s a general outline of how you might use Molecule with an Ansible role that interacts with an OpenStack environment. 

1. **Install Molecule**  
Start by installing Molecule, which is a framework designed to test Ansible roles. You can install Molecule by using the command _pip install molecule_ in your terminal.
1. **Create Ansible role**  
Develop your Ansible role or make use of an existing one that you intend to test within the OpenStack environment.
1. **Initialize Molecule**  
In the directory where your role resides, set up Molecule by initiating a new scenario using the OpenStack driver. Navigate to your role’s directory and run _molecule init role openstack.yaml_ to create a new Molecule scenario using the OpenStack driver.
1. **Configure Molecule scenario**  
Go to the scenario directory that you just created, usually named ‘molecule/default’. Adjust the ‘molecule.yml’ file in this directory to match the requirements of OpenStack. This involves specifying details like authentication credentials, images, networks, and other relevant settings.

Here’s a simplified example of what the ‘molecule.yml’ configuration might look like: 

1. **Write test scenarios**  
Inside the ‘molecule/default/tests’ directory, craft test scenarios using Ansible modules. These scenarios validate that your role behaves correctly within the OpenStack environment.
1. **Run tests**  
Execute the testing process using Molecule. To run a comprehensive test sequence, use the command _molecule test_ in your terminal. Molecule will set up a virtual environment, deploy an OpenStack instance, apply your Ansible role, perform tests, and then dismantle the environment once testing is completed.

Keep in mind that this outline provides a foundational structure, and further customization may be necessary based on your specific role and OpenStack environment. As technology evolves, OpenStack configurations may change, so it’s always recommended to consult the latest documentation for accuracy. That said, always conduct thorough testing in a controlled environment prior to implementing changes in live systems. 

![Michiel](https://fairbanks-upgrade.ubo-dev.nl/media/uploads/2025/06/Michiel.jpeg?width=500 "Michiel")

## Want to know more about open source private cloud

Let’s talk with Michiel Manten

[Let's talk](https://fairbanks-upgrade.ubo-dev.nl/contact/?subject=Example%20of%20Ansible%20Molecule%20in%20OpenStack)

Insights & resources

## Latest blogs & news

[Insights & resources](https://fairbanks-upgrade.ubo-dev.nl/insights-resources/)

[KeynoteSustainable private cloud: how to balance energy, performance and business impact![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)Sustainable private cloud: how to balance energy, performance and business impactEvent](https://fairbanks-upgrade.ubo-dev.nl/sustainable-private-cloud/)

[BlogOpenStack Hibiscus is here: What’s new in the latest release![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)October 20, 2026OpenStack Hibiscus is here: What’s new in the latest releaseTechnology](https://fairbanks-upgrade.ubo-dev.nl/openstack-hibiscus-is-here-whats-new-in-the-latest-release/)

[KeynoteHow Kubernetes and Talos make OpenStack easier to upgrade, manage and scale![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)How Kubernetes and Talos make OpenStack easier to upgrade, manage and scaleEvent](https://fairbanks-upgrade.ubo-dev.nl/how-kubernetes-and-talos-make-openstack-easier-to-upgrade-manage-and-scale/)

[KeynoteFrom infrastructure complexity to cloud control: how to orchestrate your datacenter with software![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)From infrastructure complexity to cloud control: how to orchestrate your datacenter with softwareEvent](https://fairbanks-upgrade.ubo-dev.nl/from-infrastructure-complexity-to-cloud-control-how-to-orchestrate-your-datacenter-with-software/)

[BlogDigital autonomy: looking beyond the cloud![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)September 9, 2026Digital autonomy: looking beyond the cloudTechnology](https://fairbanks-upgrade.ubo-dev.nl/digital-autonomy-looking-beyond-the-cloud/)

[BlogUpgrading OpenStack: why containerization and Kubernetes are the answer![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)August 26, 2026Upgrading OpenStack: why containerization and Kubernetes are the answerTechnology](https://fairbanks-upgrade.ubo-dev.nl/upgrading-openstack-containerization-kubernetes/)

[BlogCloud infrastructure migration: what are your options and where do you start?![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)July 24, 2026Cloud infrastructure migration: what are your options and where do you start?Technology](https://fairbanks-upgrade.ubo-dev.nl/cloud-infrastructure-migration-what-are-your-options-and-where-do-you-start/)

[BlogFairbanks named as a representative vendor in the 2026 Gartner® Market Guide![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)July 21, 2026Fairbanks named as a representative vendor in the 2026 Gartner® Market Guide for cloud infrastructure sovereign solutionsTechnology](https://fairbanks-upgrade.ubo-dev.nl/fairbanks-named-as-a-representative-vendor-in-the-2026-gartner-market-guide-for-cloud-infrastructure-sovereign-solutions/)

[BlogMutable vs. immutable infrastructure![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)June 18, 2026Mutable vs. immutable infrastructure: What it means for your datacenterTechnology](https://fairbanks-upgrade.ubo-dev.nl/mutable-vs-immutable-infrastructure-what-it-means-for-your-datacenter/)

[BlogPress release![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)June 10, 2026Press releaseEvent](https://fairbanks-upgrade.ubo-dev.nl/press-release/)

Newsletter
