From 765a08fce5bf153970ccb4c4d95aa06a4af35b55 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:50:06 +0400 Subject: [PATCH 1/5] add images cache --- molecule_qemu/playbooks/create.yml | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 6637363..4f986b8 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -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 ######################################################### @@ -98,6 +98,33 @@ 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: Set images cache + ansible.builtin.set_fact: + images: "{{ images.results | map(attribute='item') | list | zip(images.results | map(attribute='dest') | list) }}" + images_cache: {} + + - name: Set images mapping + ansible.builtin.set_fact: + images_cache: "{{ images_cache | combine({item[0]: item[1]}) }}" + loop: "{{ images }}" + ### cloud-init ############################################################ - name: Create cloud-init folders ansible.builtin.file: @@ -145,7 +172,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 }}" From 99803ce09f17ff2218672f39e040fe252414506d Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:52:05 +0400 Subject: [PATCH 2/5] update task names --- molecule_qemu/playbooks/create.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 4f986b8..8052f37 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -115,15 +115,17 @@ label: "{{ item | basename }}" register: images - - name: Set images cache + - 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 mapping + - 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 From d2528fb1f93a06fd088f75f6e16257616d3b7cbd Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:53:33 +0400 Subject: [PATCH 3/5] update image url documentation --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7174d58..4c8315c 100644 --- a/README.md +++ b/README.md @@ -28,17 +28,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 From 8aaf8e8c8ddc15ca16c6fdacc4dd23f8b8142fd8 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:57:16 +0400 Subject: [PATCH 4/5] add note about supported platforms --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c8315c..6de285e 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,22 @@ 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 From 10bc99bd7018d95ce6948e0335ecdb21a10739fb Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:57:42 +0400 Subject: [PATCH 5/5] add empty line --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6de285e..466f8a9 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Install QEMU and CDRTools on macOS: ```bash brew install qemu cdrtools ``` + Supported platforms: * MacOS 13.x (aaarch64)