Skip to content

Commit 4af6d6b

Browse files
authored
Merge pull request #15 from theko2fi/molecule_multipass
Molecule multipass driver
2 parents 380876c + f1c1358 commit 4af6d6b

File tree

13 files changed

+234
-0
lines changed

13 files changed

+234
-0
lines changed

roles/molecule_multipass/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Molecule Multipass driver
2+
=========================
3+
4+
Multipass driver for Molecule.
5+
6+
Requirements
7+
------------
8+
9+
This role requires the following tools to be installed:
10+
- [multipass](https://multipass.run/)
11+
- [molecule](https://ansible.readthedocs.io/projects/molecule/)
12+
13+
How to use?
14+
-----------
15+
16+
This section is being written. Coming soon...
17+
18+
License
19+
-------
20+
21+
GNU General Public License v3.0 or later
22+
23+
Author Information
24+
------------------
25+
26+
Created by Kenneth KOFFI, you can reach him on the following platforms:
27+
- medium: https://theko2fi.medium.com
28+
- github: https://github.com/theko2fi
29+
- linkedin: https://www.linkedin.com/in/kenneth-koffi-6b1218178
30+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
# defaults file for theko2fi.multipass.molecule
3+
dest: "{{ ('molecule/' + (scenario_name | default('default'))) | realpath }}"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# handlers file for theko2fi.multipass.molecule
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
galaxy_info:
2+
author: your name
3+
description: your role description
4+
company: your company (optional)
5+
6+
# If the issue tracker for your role is not on github, uncomment the
7+
# next line and provide a value
8+
# issue_tracker_url: http://example.com/issue/tracker
9+
10+
# Choose a valid license ID from https://spdx.org - some suggested licenses:
11+
# - BSD-3-Clause (default)
12+
# - MIT
13+
# - GPL-2.0-or-later
14+
# - GPL-3.0-only
15+
# - Apache-2.0
16+
# - CC-BY-4.0
17+
license: license (GPL-2.0-or-later, MIT, etc)
18+
19+
min_ansible_version: 2.1
20+
21+
# If this a Container Enabled role, provide the minimum Ansible Container version.
22+
# min_ansible_container_version:
23+
24+
#
25+
# Provide a list of supported platforms, and for each platform a list of versions.
26+
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
27+
# To view available platforms and versions (or releases), visit:
28+
# https://galaxy.ansible.com/api/v1/platforms/
29+
#
30+
# platforms:
31+
# - name: Fedora
32+
# versions:
33+
# - all
34+
# - 25
35+
# - name: SomePlatform
36+
# versions:
37+
# - all
38+
# - 1.0
39+
# - 7
40+
# - 99.99
41+
42+
galaxy_tags: []
43+
# List tags for your role here, one per line. A tag is a keyword that describes
44+
# and categorizes the role. Users find roles by searching for tags. Be sure to
45+
# remove the '[]' above, if you add tags to this list.
46+
#
47+
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
48+
# Maximum 20 tags per role.
49+
50+
dependencies: []
51+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
52+
# if you add dependencies to this list.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
# tasks file for theko2fi.multipass.molecule
3+
4+
- name: Check if destination folder exists
5+
ansible.builtin.file:
6+
path: "{{ dest }}"
7+
state: directory
8+
mode: "0700"
9+
- name: Check if destination folder is empty
10+
ansible.builtin.find:
11+
paths: "{{ dest }}"
12+
register: dest_content
13+
- name: Fail if destination folder is not empty
14+
when: dest_content.matched > 0
15+
ansible.builtin.fail:
16+
msg: Refused to expand templates as destination folder '{{ dest }}' as it already has content in it.
17+
- name: Expand templates
18+
vars:
19+
dest_file: "{{ dest }}/{{ item | basename | regex_replace('\\.j2$', '') }}"
20+
ansible.builtin.template:
21+
src: "{{ item }}"
22+
dest: "{{ dest_file }}"
23+
mode: "0644"
24+
with_fileglob:
25+
- templates/scenario/*.j2
26+
loop_control:
27+
label: "{{ dest_file | relpath }}"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
gather_facts: true
5+
tasks:
6+
- name: Replace this task with one that validates your content
7+
ansible.builtin.debug:
8+
msg: "This is the effective test"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
{% raw -%}
3+
- name: Create
4+
hosts: localhost
5+
connection: local
6+
gather_facts: false
7+
no_log: "{{ molecule_no_log }}"
8+
vars:
9+
molecule_labels:
10+
owner: molecule
11+
tags:
12+
- always
13+
tasks:
14+
- name: Set async_dir for HOME env
15+
ansible.builtin.set_fact:
16+
ansible_async_dir: "{{ lookup('env', 'HOME') }}/.ansible_async/"
17+
when: (lookup('env', 'HOME'))
18+
19+
- name: Create molecule instance(s)
20+
theko2fi.multipass.multipass_vm:
21+
name: "{{ item.name }}"
22+
cloud_init: "{{ item.cloud_init | default(omit) }}"
23+
cpus: "{{ item.cpu | default(omit) }}"
24+
disk: "{{ item.disk | default(omit) }}"
25+
image: "{{ item.image | default(omit) }}"
26+
memory: "{{ item.memory | default(omit) }}"
27+
recreate: "{{ item.recreate | default(omit) }}"
28+
state: 'started'
29+
register: server
30+
with_items: "{{ molecule_yml.platforms }}"
31+
loop_control:
32+
label: "{{ item.name }}"
33+
no_log: false
34+
async: 7200
35+
poll: 0
36+
37+
- name: Wait for instance(s) creation to complete
38+
ansible.builtin.async_status:
39+
jid: "{{ item.ansible_job_id }}"
40+
register: multipass_jobs
41+
until: multipass_jobs.finished
42+
retries: 300
43+
with_items: "{{ server.results }}"
44+
{%- endraw %}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
{% raw -%}
3+
- name: Destroy
4+
hosts: localhost
5+
connection: local
6+
gather_facts: false
7+
no_log: "{{ molecule_no_log }}"
8+
tags:
9+
- always
10+
tasks:
11+
- name: Set async_dir for HOME env
12+
ansible.builtin.set_fact:
13+
ansible_async_dir: "{{ lookup('env', 'HOME') }}/.ansible_async/"
14+
when: (lookup('env', 'HOME'))
15+
16+
- name: Destroy molecule instance(s)
17+
theko2fi.multipass.multipass_vm:
18+
name: "{{ item.name }}"
19+
state: absent
20+
purge: true
21+
register: server
22+
loop: "{{ molecule_yml.platforms }}"
23+
loop_control:
24+
label: "{{ item.name }}"
25+
no_log: false
26+
async: 7200
27+
poll: 0
28+
29+
- name: Wait for instance(s) deletion to complete
30+
ansible.builtin.async_status:
31+
jid: "{{ item.ansible_job_id }}"
32+
register: multipass_jobs
33+
until: multipass_jobs.finished
34+
retries: 300
35+
loop: "{{ server.results }}"
36+
loop_control:
37+
label: "{{ item.item.name }}"
38+
39+
{%- endraw %}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
options:
6+
managed: False
7+
login_cmd_template: 'multipass exec {instance} -- bash'
8+
ansible_connection_options:
9+
ansible_connection: theko2fi.multipass.multipass
10+
platforms:
11+
- name: instance-molecule
12+
provisioner:
13+
name: ansible
14+
verifier:
15+
name: ansible
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
collections:
2+
- theko2fi.multipass

0 commit comments

Comments
 (0)