Search code examples
openstackmolecule

How to use molecule with Openstack


I use molecule a lot with the docker driver. There are a few cases where docker is not the right tool to test ansible roles against, so I'd like to spin up a vm in openstack.

I've created an ansible role with molecule role -r <rolename> and changed the driver in molecule.yml to 'openstack'. This is an example of my current molecule.yml:

---
dependency:
  name: galaxy
driver:
  name: openstack
lint:
  name: yamllint
platforms:
  - name: molecule-role-docker
    image: CentOS7
    flavor: ECS.UC1.4-4
    auto_ip: true
    security_groups: ssh
    key_name: mykey-ci
provisioner:
  name: ansible
  lint:
    name: ansible-lint
verifier:
  name: testinfra
  lint:
    name: flake8

Unfortunately there seems to be the create.yml file missing, which spins up the machine:

[...]
Validation completed successfully.
--> Test matrix

└── default
    ├── dependency
    ├── create
    ├── prepare
    └── converge

--> Scenario: 'default'
--> Action: 'dependency'
Skipping, missing the requirements file.
--> Scenario: 'default'
--> Action: 'create'
ERROR! the playbook: None could not be found
ERROR:

If I create an create.yml file, the error message indicates it found the file empty:

[...]
--> Scenario: 'default'
--> Action: 'create'
ERROR! Empty playbook, nothing to do
ERROR:

So, how do I get the openstack driver to work and how do I create and prepare a virtual machine to run my checks against it?

I use molecule 2.22, ansible 2.9.4 and python 3.7.6.

As suggested in the documentation, I have already installed the molecule openstack plugin: pip3 install 'molecule[openstack]'


Solution

  • The default driver is docker. You should create your role from start with the openstack driver. This will put the correct setting for you in molecule.yml as well as create the necessary base files in your default scenario:

    molecule init role -d openstack -r my_role
    

    You can as well init a new scenario in an existing role. From the root of your role

    molecule init scenario -d openstack -s my_scenario