Added native Molecule jobs

Change-Id: Idaabccf0387e88e443354ee0100492e702018453
This commit is contained in:
Mohammed Naser 2022-04-29 19:50:16 -04:00
parent cf56d9c62b
commit 2c1ff7f6c3
7 changed files with 126 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
- hosts: ubuntu-focal
tasks:
- shell: "{{ molecule_executable }} destroy"

View File

@ -0,0 +1,36 @@
---
- hosts: ubuntu-focal
roles:
- role: ensure-clouds-yaml
- role: ensure-molecule
vars:
molecule_version: 3.5.2
- hosts: ubuntu-focal
tasks:
- shell: "{{ molecule_executable }} prepare"
- hosts: localhost
tasks:
- name: Grab the Molecule instance configuration
set_fact:
molecule_instance_config: "{{ lookup('file', molecule_instance_config_path) | from_yaml }}"
vars:
molecule_instance_config_path: "{{ ansible_user_dir }}/.cache/molecule/{{ zuul.project.short_name }}/default/instance_config.yml"
- name: Add all of the hosts to the inventory
add_host:
name: "{{ item.instance }}"
ansible_user: "{{ item.user }}"
ansible_host: "{{ item.address }}"
ansible_port: "{{ item.port }}"
ansible_private_key_file: "{{ item.identity_file }}"
ansible_ssh_extra_args: -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
loop: "{{ molecule_instance_config }}"
loop_control:
label: "{{ item.instance }}"
- hosts: all
tasks:
- ping:

View File

@ -0,0 +1,6 @@
---
- hosts: ubuntu-focal
tasks:
- shell: "{{ molecule_executable }} converge"
- shell: "{{ molecule_executable }} idempotence"
- shell: "{{ molecule_executable }} verify"

View File

@ -0,0 +1,25 @@
Ensure Molecule is installed
Look for ``molecule``, and if not found, install it via ``pip`` into a
virtual environment for the current user.
**Role Variables**
.. zuul:rolevar:: molecule_version
:default: 3.6.1
Molecule version to install on the host.
**Output Variables**
.. zuul:rolevar:: molecule_executable
:default: molecule
After running this role, ``molecule_executable`` will be set as the path
to a valid ``molecule``.
At role runtime, look for an existing ``molecule`` at this specific
path. Note the default (``molecule``) effectively means to find tox in
the current ``$PATH``. For example, if your base image
pre-installs molecule in an out-of-path environment, set this so the
role does not attempt to install the user version.

View File

@ -0,0 +1,2 @@
molecule_executable: molecule
molecule_venv_path: '{{ ansible_user_dir }}/.local/molecule'

View File

@ -0,0 +1,34 @@
- name: Install pip
include_role:
name: ensure-pip
- name: Check if molecule is installed
shell: |
command -v {{ molecule_executable }} {{ molecule_venv_path }}/bin/molecule || exit 1
args:
executable: /bin/bash
register: molecule_preinstalled
failed_when: false
- name: Export preinstalled molecule_executable
set_fact:
molecule_executable: '{{ molecule_preinstalled.stdout_lines[0] }}'
cacheable: true
when: molecule_preinstalled.rc == 0
- name: Install molecule to local env
when: molecule_preinstalled.rc != 0
block:
- name: Create local venv
command: '{{ ensure_pip_virtualenv_command }} {{ molecule_venv_path }}'
- name: Install molecule to local venv
command: '{{ molecule_venv_path }}/bin/pip install molecule'
- name: Export installed molecule_executable path
set_fact:
molecule_executable: '{{ molecule_venv_path }}/bin/molecule'
cacheable: true
- name: Output molecule version
command: "{{ molecule_executable }} --version"

View File

@ -13,6 +13,25 @@
tox_environment:
OS_CLOUD: default
- job:
name: molecule
allowed-projects:
- vexxhost/ansible-collection-atmosphere
pre-run:
- playbooks/molecule/pre-run.yaml
run:
- playbooks/molecule/run.yaml
post-run:
- playbooks/molecule/post-run.yaml
cleanup-run:
- playbooks/molecule/post-run.yaml
secrets:
- name: openstack_credentials
secret: vexxhost-openstack
vars:
tox_environment:
OS_CLOUD: default
- job:
name: vexxhost-build-docker-image
parent: opendev-build-docker-image