Skip to content

Commit

Permalink
Merge pull request #4 from andreygubarev/feature-remote-images
Browse files Browse the repository at this point in the history
feature remote images
  • Loading branch information
andreygubarev authored May 26, 2023
2 parents f135b58 + 10bc99b commit adf9c8f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ Molecule QEMU driver for testing Ansible roles.
pip install molecule-qemu
```

## Dependencies
Install QEMU and CDRTools on macOS:

```bash
brew install qemu cdrtools
```

Supported platforms:
* MacOS 13.x (aaarch64)

Support guest OS:
* Ubuntu 20.04 LTS (aarch64)
* Ubuntu 20.04 LTS (x86_64)
* Debian 11 (x86_64)

Support of other platforms and guest OS is possible, but not tested.

# Examples

## Example scenario
```bash
molecule init scenario scenario_name -d molecule-qemu
Expand All @@ -28,17 +40,17 @@ driver:
name: molecule-qemu
platforms:
- name: ubuntu-1
image: ~/Downloads/focal-server-cloudimg-arm64.img
image: file:///Users/andrey/Downloads/focal-server-cloudimg-arm64.img
image_arch: aarch64
ssh_port: 10022
ssh_user: ubuntu
- name: ubuntu-2
image: ~/Downloads/focal-server-cloudimg-amd64.img
image: file:///Users/andrey/Downloads/focal-server-cloudimg-amd64.img
image_arch: x86_64 # default
ssh_port: 10023
ssh_user: ubuntu
- name: debian-1
image: ~/Downloads/debian-11-generic-amd64.qcow2
image: file:///Users/andrey/Downloads/debian-11-generic-amd64.qcow2
image_arch: x86_64 # default
ssh_port: 10024
ssh_user: debian
Expand Down
33 changes: 31 additions & 2 deletions molecule_qemu/playbooks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
qemu_vm_image_arch: "x86_64"
qemu_vm_image_format: "qcow2"
qemu_vm_memory: "1024"
qemu_vm_cpus: "1"
qemu_vm_cpus: "2"

tasks:
### configuration #########################################################
Expand Down Expand Up @@ -98,6 +98,35 @@
mode: "0644"
when: "'aarch64' in molecule_instances | map(attribute='image_arch') | list | unique"

### images ###############################################################
- name: Create images directory
ansible.builtin.file:
path: "{{ molecule_ephemeral_directory }}/run/images/"
state: directory
mode: "0755"

- name: Fetch images
ansible.builtin.get_url:
url: "{{ item }}"
dest: "{{ molecule_ephemeral_directory }}/run/images/{{ item | basename }}"
mode: "0644"
loop: "{{ molecule_instances | map(attribute='image') | list | unique }}"
loop_control:
label: "{{ item | basename }}"
register: images

- name: Get images
ansible.builtin.set_fact:
images: "{{ images.results | map(attribute='item') | list | zip(images.results | map(attribute='dest') | list) }}"
images_cache: {}

- name: Set images cache
ansible.builtin.set_fact:
images_cache: "{{ images_cache | combine({item[0]: item[1]}) }}"
loop: "{{ images }}"
loop_control:
label: "{{ item[0] | basename }}"

### cloud-init ############################################################
- name: Create cloud-init folders
ansible.builtin.file:
Expand Down Expand Up @@ -145,7 +174,7 @@
ansible.builtin.command: >
qemu-img create
-f qcow2
-o backing_file={{ item.image }},backing_fmt={{ item.image_format }}
-o backing_file={{ images_cache[item.image] }},backing_fmt={{ item.image_format }}
{{ item.path_disk }}
args:
creates: "{{ item.path_disk }}"
Expand Down

0 comments on commit adf9c8f

Please sign in to comment.