diff --git a/README.md b/README.md index 7174d58..466f8a9 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 6637363..8052f37 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,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: @@ -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 }}"