From 599c1b991d063bc473f2c26d04b593920fa8f550 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 08:03:31 +0400 Subject: [PATCH 01/13] parse configuration first --- molecule_qemu/playbooks/create.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 9ff83c3..26ce686 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -12,18 +12,6 @@ qemu_vm_memory: "1024" tasks: - - name: Create run directory exists - ansible.builtin.file: - path: "{{ molecule_ephemeral_directory }}/run/" - state: directory - mode: "0755" - - - name: Generate OpenSSH key pair - community.crypto.openssh_keypair: - path: "{{ molecule_ephemeral_directory }}/run/id_ed25519" - type: ed25519 - register: vm_ssh_keypair - - name: Register VMs data ansible.builtin.set_fact: instance: { @@ -44,6 +32,18 @@ label: "{{ item.name }}" register: molecule_instances + - name: Create run directory exists + ansible.builtin.file: + path: "{{ molecule_ephemeral_directory }}/run/" + state: directory + mode: "0755" + + - name: Generate OpenSSH key pair + community.crypto.openssh_keypair: + path: "{{ molecule_ephemeral_directory }}/run/id_ed25519" + type: ed25519 + register: vm_ssh_keypair + - name: Prepare VMs data ansible.builtin.set_fact: molecule_instances: "{{ molecule_instances.results | map(attribute='ansible_facts.instance') | list }}" From 33c5c30852a72bd117361170547e9508c7a06937 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 08:11:56 +0400 Subject: [PATCH 02/13] add assertion for configuration validate --- molecule_qemu/playbooks/create.yml | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 26ce686..ca76f1b 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -32,6 +32,30 @@ label: "{{ item.name }}" register: molecule_instances + - name: Prepare VMs data + ansible.builtin.set_fact: + molecule_instances: "{{ molecule_instances.results | map(attribute='ansible_facts.instance') | list }}" + + - name: Validate VMs configuration + ansible.builtin.assert: + that: + - molecule_instances is defined + - molecule_instances | length > 0 + - molecule_instances | length == molecule_yml.platforms | length + - molecule_instances | map(attribute='vm_ssh_port') | list | unique | length == molecule_instances | length + fail_msg: "Molecule instances are not properly defined" + success_msg: "Molecule instances are properly defined" + + - name: Validate supported VMs configuration + ansible.builtin.assert: + that: + - item.vm_arch in ['x86_64', 'aarch64'] + fail_msg: "Molecule instance {{ item.name }} configuration is not supported" + success_msg: "Molecule instance {{ item.name }} configuration is supported" + loop: "{{ molecule_instances }}" + loop_control: + label: "{{ item.name }}" + - name: Create run directory exists ansible.builtin.file: path: "{{ molecule_ephemeral_directory }}/run/" @@ -44,9 +68,6 @@ type: ed25519 register: vm_ssh_keypair - - name: Prepare VMs data - ansible.builtin.set_fact: - molecule_instances: "{{ molecule_instances.results | map(attribute='ansible_facts.instance') | list }}" - name: Create VMs disks based on provided image ansible.builtin.command: > From 000a5494b9b6f73bca4c2cab3a571cfacd4cf35e Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 08:28:48 +0400 Subject: [PATCH 03/13] add bios for arm instances --- molecule_qemu/playbooks/create.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index ca76f1b..b587dfc 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -68,6 +68,11 @@ type: ed25519 register: vm_ssh_keypair + - name: Download bios for ARM VMs + ansible.builtin.get_url: + url: "https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/QEMU_EFI.fd" + dest: "{{ molecule_ephemeral_directory }}/run/QEMU_EFI.fd" + when: "'aarch64' in molecule_instances | map(attribute='vm_arch') | list | unique" - name: Create VMs disks based on provided image ansible.builtin.command: > @@ -134,6 +139,12 @@ -display none -daemonize -pidfile {{ item.vm_run_pidfile }} + {% if item.vm_arch == 'aarch64' %} + -bios {{ molecule_ephemeral_directory }}/run/QEMU_EFI.fd + -cpu cortex-a72 + -machine virt,highmem=off + -accel hvf + {% endif %} loop: "{{ molecule_instances }}" loop_control: label: "{{ item.name }}" From c62bb49049c483a39d8c5665552682f6a4f8d798 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 08:28:53 +0400 Subject: [PATCH 04/13] fix message --- molecule_qemu/playbooks/create.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index b587dfc..ea8ac57 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -56,7 +56,7 @@ loop_control: label: "{{ item.name }}" - - name: Create run directory exists + - name: Create run directory ansible.builtin.file: path: "{{ molecule_ephemeral_directory }}/run/" state: directory From 7f3813b3662d16ab50aaee48742d9e6d7fb4149b Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 08:45:14 +0400 Subject: [PATCH 05/13] add hvf support --- molecule_qemu/playbooks/create.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index ea8ac57..434672a 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -10,6 +10,7 @@ molecule_project_name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}" qemu_vm_arch: "x86_64" qemu_vm_memory: "1024" + qemu_vm_support_hvf: false tasks: - name: Register VMs data @@ -74,6 +75,17 @@ dest: "{{ molecule_ephemeral_directory }}/run/QEMU_EFI.fd" when: "'aarch64' in molecule_instances | map(attribute='vm_arch') | list | unique" + - name: Check kern.hv_support + command: sysctl kern.hv_support + register: hv_support + changed_when: False + ignore_errors: True + + - name: Determine hv support + set_fact: + qemu_vm_support_hvf: "{{ hv_support.stdout | trim == 'kern.hv_support: 1' }}" + when: hv_support is defined + - name: Create VMs disks based on provided image ansible.builtin.command: > qemu-img create @@ -130,6 +142,7 @@ - name: Launch VMs # noqa: no-changed-when ansible.builtin.command: > qemu-system-{{ item.vm_arch }} + -name {{ item.name }} -boot d -cdrom {{ molecule_ephemeral_directory }}/run/cloud-init/{{ item.name }}.iso -hda {{ item.vm_run_diskfile }} @@ -143,8 +156,10 @@ -bios {{ molecule_ephemeral_directory }}/run/QEMU_EFI.fd -cpu cortex-a72 -machine virt,highmem=off + {% if qemu_vm_support_hvf %} -accel hvf {% endif %} + {% endif %} loop: "{{ molecule_instances }}" loop_control: label: "{{ item.name }}" From 9f374a7dcf5cf47eff0be277127615f41a64cb29 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:05:12 +0400 Subject: [PATCH 06/13] refactoring --- molecule_qemu/playbooks/create.yml | 123 ++++++++++-------- .../playbooks/templates/user-data.j2 | 2 +- 2 files changed, 68 insertions(+), 57 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 434672a..8927a1b 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -8,25 +8,29 @@ molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}" molecule_scenario_name: "{{ lookup('env', 'MOLECULE_SCENARIO_NAME') }}" molecule_project_name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}" - qemu_vm_arch: "x86_64" - qemu_vm_memory: "1024" - qemu_vm_support_hvf: false + qemu_host_capability_hvf: false + qemu_guest_image_arch: "x86_64" + qemu_guest_image_format: "qcow2" + qemu_guest_memory: "1024" + qemu_guest_cpus: "1" tasks: + ### configuration ######################################################### - name: Register VMs data ansible.builtin.set_fact: instance: { "instance": "molecule-{{ molecule_project_name }}-{{ molecule_scenario_name }}-{{ item.name }}", "name": "{{ item.name }}", - "vm_arch": "{{ item.vm_arch | default(qemu_vm_arch) }}", - "vm_image": "{{ item.vm_image }}", - "vm_image_format": "{{ item.vm_image_format | default('qcow2') }}", - "vm_memory": "{{ item.vm_memory | default(qemu_vm_memory) }}", - "vm_ssh_host": "{{ item.vm_ssh_host | default('127.0.0.1') }}", - "vm_ssh_port": "{{ item.vm_ssh_port | default(10022) }}", - "vm_ssh_user": "{{ item.vm_ssh_user | default('debian') }}", - "vm_run_pidfile": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.pid", - "vm_run_diskfile": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.qcow2", + "image": "{{ item.vm_image }}", + "image_arch": "{{ item.vm_image_arch | default(qemu_guest_image_arch) }}", + "image_format": "{{ item.vm_image_format | default(qemu_guest_image_format) }}", + "path_disk": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.qcow2", + "path_pid": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.pid", + "ssh_host": "{{ item.ssh_host | default('127.0.0.1') }}", + "ssh_port": "{{ item.ssh_port | default(10022) }}", + "ssh_user": "{{ item.vm_ssh_user | default('debian') }}", + "vm_cpus": "{{ item.vm_cpus | default(qemu_guest_cpus) }}", + "vm_memory": "{{ item.vm_memory | default(qemu_guest_memory) }}", } loop: "{{ molecule_yml.platforms }}" loop_control: @@ -37,67 +41,59 @@ ansible.builtin.set_fact: molecule_instances: "{{ molecule_instances.results | map(attribute='ansible_facts.instance') | list }}" - - name: Validate VMs configuration + ### assertions ############################################################ + - name: Assert VMs configuration ansible.builtin.assert: that: - molecule_instances is defined - molecule_instances | length > 0 - molecule_instances | length == molecule_yml.platforms | length - - molecule_instances | map(attribute='vm_ssh_port') | list | unique | length == molecule_instances | length + - molecule_instances | map(attribute='ssh_port') | list | unique | length == molecule_instances | length fail_msg: "Molecule instances are not properly defined" success_msg: "Molecule instances are properly defined" - - name: Validate supported VMs configuration + - name: Assert supported VMs configuration ansible.builtin.assert: that: - - item.vm_arch in ['x86_64', 'aarch64'] + - item.image_arch in ['x86_64', 'aarch64'] fail_msg: "Molecule instance {{ item.name }} configuration is not supported" success_msg: "Molecule instance {{ item.name }} configuration is supported" loop: "{{ molecule_instances }}" loop_control: label: "{{ item.name }}" + ### capabilities ########################################################## + - name: Read kern.hv_support + command: sysctl kern.hv_support + register: hv_support + changed_when: False + ignore_errors: True + + - name: Set hvf support + set_fact: + qemu_host_capability_hvf: "{{ hv_support.stdout | trim == 'kern.hv_support: 1' }}" + when: hv_support is defined + + ### prerequisites ######################################################### - name: Create run directory ansible.builtin.file: path: "{{ molecule_ephemeral_directory }}/run/" state: directory mode: "0755" - - name: Generate OpenSSH key pair + - name: Create OpenSSH key pair community.crypto.openssh_keypair: path: "{{ molecule_ephemeral_directory }}/run/id_ed25519" type: ed25519 - register: vm_ssh_keypair + register: ssh_keypair - - name: Download bios for ARM VMs + - name: Fetch ARM VMs bios ansible.builtin.get_url: url: "https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/QEMU_EFI.fd" dest: "{{ molecule_ephemeral_directory }}/run/QEMU_EFI.fd" - when: "'aarch64' in molecule_instances | map(attribute='vm_arch') | list | unique" - - - name: Check kern.hv_support - command: sysctl kern.hv_support - register: hv_support - changed_when: False - ignore_errors: True - - - name: Determine hv support - set_fact: - qemu_vm_support_hvf: "{{ hv_support.stdout | trim == 'kern.hv_support: 1' }}" - when: hv_support is defined - - - name: Create VMs disks based on provided image - ansible.builtin.command: > - qemu-img create - -f qcow2 - -o backing_file={{ item.vm_image }},backing_fmt={{ item.vm_image_format }} - {{ item.vm_run_diskfile }} - args: - creates: "{{ item.vm_run_diskfile }}" - loop: "{{ molecule_instances }}" - loop_control: - label: "{{ item.name }}" + when: "'aarch64' in molecule_instances | map(attribute='image_arch') | list | unique" + ### cloud-init ############################################################ - name: Create cloud-init folders ansible.builtin.file: path: "{{ molecule_ephemeral_directory }}/run/cloud-init/{{ item.name }}/" @@ -139,24 +135,37 @@ loop_control: label: "{{ item.name }}" + ### qemu ################################################################## + - name: Create VMs disks + ansible.builtin.command: > + qemu-img create + -f qcow2 + -o backing_file={{ item.image }},backing_fmt={{ item.image_format }} + {{ item.path_disk }} + args: + creates: "{{ item.path_disk }}" + loop: "{{ molecule_instances }}" + loop_control: + label: "{{ item.name }}" + - name: Launch VMs # noqa: no-changed-when ansible.builtin.command: > - qemu-system-{{ item.vm_arch }} + qemu-system-{{ item.image_arch }} -name {{ item.name }} -boot d -cdrom {{ molecule_ephemeral_directory }}/run/cloud-init/{{ item.name }}.iso - -hda {{ item.vm_run_diskfile }} + -hda {{ item.path_disk }} -m {{ item.vm_memory }} -net nic - -net user,hostfwd=tcp::{{ item.vm_ssh_port }}-:22 + -net user,hostfwd=tcp::{{ item.ssh_port }}-:22 -display none -daemonize - -pidfile {{ item.vm_run_pidfile }} - {% if item.vm_arch == 'aarch64' %} + -pidfile {{ item.path_pid }} + {% if item.image_arch == 'aarch64' %} -bios {{ molecule_ephemeral_directory }}/run/QEMU_EFI.fd -cpu cortex-a72 -machine virt,highmem=off - {% if qemu_vm_support_hvf %} + {% if qemu_host_capability_hvf %} -accel hvf {% endif %} {% endif %} @@ -164,10 +173,11 @@ loop_control: label: "{{ item.name }}" + ### ssh ################################################################### - name: Wait for SSH to be ready ansible.builtin.wait_for: - host: "{{ item.vm_ssh_host }}" - port: "{{ item.vm_ssh_port }}" + host: "{{ item.ssh_host }}" + port: "{{ item.ssh_port }}" delay: 5 timeout: 180 search_regex: "OpenSSH" @@ -189,17 +199,18 @@ retries: 30 delay: 10 + ### molecule ############################################################## - name: Prepare VMs config dict ansible.builtin.set_fact: instance_conf_dict: { "instance": "{{ item.instance }}", "name": "{{ item.name }}", - "address": "{{ item.vm_ssh_host }}", + "address": "{{ item.ssh_host }}", "user": "{{ item.vm_ssh_user }}", - "port": "{{ item.vm_ssh_port }}", - "identity_file": "{{ vm_ssh_keypair.filename }}", - "pidfile": "{{ item.vm_run_pidfile }}", - "diskfile": "{{ item.vm_run_diskfile }}", + "port": "{{ item.ssh_port }}", + "identity_file": "{{ ssh_keypair.filename }}", + "pidfile": "{{ item.path_pid }}", + "diskfile": "{{ item.path_disk }}", } loop: "{{ molecule_instances }}" loop_control: diff --git a/molecule_qemu/playbooks/templates/user-data.j2 b/molecule_qemu/playbooks/templates/user-data.j2 index 389babe..eb84d90 100644 --- a/molecule_qemu/playbooks/templates/user-data.j2 +++ b/molecule_qemu/playbooks/templates/user-data.j2 @@ -1,6 +1,6 @@ #cloud-config ssh_authorized_keys: -- {{ vm_ssh_keypair.public_key }} +- {{ ssh_keypair.public_key }} output: all: ">> /var/log/cloud-init-output.log" From 81c33eae5d40d3ede0072f478b22a596ff72a417 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:08:26 +0400 Subject: [PATCH 07/13] refactor vars --- molecule_qemu/playbooks/create.yml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 8927a1b..ccd49ee 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -21,16 +21,20 @@ instance: { "instance": "molecule-{{ molecule_project_name }}-{{ molecule_scenario_name }}-{{ item.name }}", "name": "{{ item.name }}", - "image": "{{ item.vm_image }}", - "image_arch": "{{ item.vm_image_arch | default(qemu_guest_image_arch) }}", - "image_format": "{{ item.vm_image_format | default(qemu_guest_image_format) }}", - "path_disk": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.qcow2", - "path_pid": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.pid", + + "image": "{{ item.image }}", + "image_arch": "{{ item.image_arch | default(qemu_guest_image_arch) }}", + "image_format": "{{ item.image_format | default(qemu_guest_image_format) }}", + "ssh_host": "{{ item.ssh_host | default('127.0.0.1') }}", "ssh_port": "{{ item.ssh_port | default(10022) }}", - "ssh_user": "{{ item.vm_ssh_user | default('debian') }}", + "ssh_user": "{{ item.ssh_user | default('debian') }}", + "vm_cpus": "{{ item.vm_cpus | default(qemu_guest_cpus) }}", "vm_memory": "{{ item.vm_memory | default(qemu_guest_memory) }}", + + "path_disk": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.qcow2", + "path_pid": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.pid", } loop: "{{ molecule_yml.platforms }}" loop_control: @@ -206,7 +210,7 @@ "instance": "{{ item.instance }}", "name": "{{ item.name }}", "address": "{{ item.ssh_host }}", - "user": "{{ item.vm_ssh_user }}", + "user": "{{ item.ssh_user }}", "port": "{{ item.ssh_port }}", "identity_file": "{{ ssh_keypair.filename }}", "pidfile": "{{ item.path_pid }}", From ba4cfee8c68572bec76fda2e170afc3277e99525 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:10:45 +0400 Subject: [PATCH 08/13] update readme --- README.md | 16 ++++++++++------ molecule_qemu/playbooks/create.yml | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e7db734..64fe1bd 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,16 @@ dependency: driver: name: molecule-qemu platforms: - - name: instance-1 - vm_image: ~/Downloads/debian-11-generic-amd64.qcow2 - vm_ssh_port: 10022 - - name: instance-2 - vm_image: ~/Downloads/debian-11-generic-amd64.qcow2 - vm_ssh_port: 10023 + - name: ubuntu-1 + image: ~/Downloads/focal-server-cloudimg-arm64.img + image_arch: aarch64 + ssh_port: 10022 + ssh_user: ubuntu + - name: debian-1 + image: ~/Downloads/debian-11-generic-amd64.qcow2 + image_arch: x86_64 # default + ssh_port: 10023 + ssh_user: debian provisioner: name: ansible diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index ccd49ee..03c1e30 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -28,7 +28,7 @@ "ssh_host": "{{ item.ssh_host | default('127.0.0.1') }}", "ssh_port": "{{ item.ssh_port | default(10022) }}", - "ssh_user": "{{ item.ssh_user | default('debian') }}", + "ssh_user": "{{ item.ssh_user }}", "vm_cpus": "{{ item.vm_cpus | default(qemu_guest_cpus) }}", "vm_memory": "{{ item.vm_memory | default(qemu_guest_memory) }}", From c329c5dc767bf38f09c8e4739e94fcc4b2ac0333 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:13:48 +0400 Subject: [PATCH 09/13] add cpus support --- molecule_qemu/playbooks/create.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 03c1e30..e12a7de 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -160,6 +160,7 @@ -cdrom {{ molecule_ephemeral_directory }}/run/cloud-init/{{ item.name }}.iso -hda {{ item.path_disk }} -m {{ item.vm_memory }} + -smp {{ item.vm_cpus }} -net nic -net user,hostfwd=tcp::{{ item.ssh_port }}-:22 -display none From e59de73aabdc709e28056d716ea93983278ce0ca Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:16:19 +0400 Subject: [PATCH 10/13] update job names --- molecule_qemu/playbooks/create.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index e12a7de..91ebc71 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -179,7 +179,7 @@ label: "{{ item.name }}" ### ssh ################################################################### - - name: Wait for SSH to be ready + - name: Wait for SSH ansible.builtin.wait_for: host: "{{ item.ssh_host }}" port: "{{ item.ssh_port }}" @@ -193,7 +193,7 @@ poll: 0 register: qemu_launch - - name: Wait for launch jobs to finish + - name: Wait for SSH to be ready ansible.builtin.async_status: jid: "{{ item.ansible_job_id }}" loop: "{{ qemu_launch.results }}" From aa1eaf34bbb5513011fe621470cecb89e898e03e Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:17:38 +0400 Subject: [PATCH 11/13] rename vars --- molecule_qemu/playbooks/create.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 91ebc71..161d41f 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -8,11 +8,11 @@ molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}" molecule_scenario_name: "{{ lookup('env', 'MOLECULE_SCENARIO_NAME') }}" molecule_project_name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}" - qemu_host_capability_hvf: false - qemu_guest_image_arch: "x86_64" - qemu_guest_image_format: "qcow2" - qemu_guest_memory: "1024" - qemu_guest_cpus: "1" + qemu_cap_hvf: false + qemu_vm_image_arch: "x86_64" + qemu_vm_image_format: "qcow2" + qemu_vm_memory: "1024" + qemu_vm_cpus: "1" tasks: ### configuration ######################################################### @@ -23,15 +23,15 @@ "name": "{{ item.name }}", "image": "{{ item.image }}", - "image_arch": "{{ item.image_arch | default(qemu_guest_image_arch) }}", - "image_format": "{{ item.image_format | default(qemu_guest_image_format) }}", + "image_arch": "{{ item.image_arch | default(qemu_vm_image_arch) }}", + "image_format": "{{ item.image_format | default(qemu_vm_image_format) }}", "ssh_host": "{{ item.ssh_host | default('127.0.0.1') }}", "ssh_port": "{{ item.ssh_port | default(10022) }}", "ssh_user": "{{ item.ssh_user }}", - "vm_cpus": "{{ item.vm_cpus | default(qemu_guest_cpus) }}", - "vm_memory": "{{ item.vm_memory | default(qemu_guest_memory) }}", + "vm_cpus": "{{ item.vm_cpus | default(qemu_vm_cpus) }}", + "vm_memory": "{{ item.vm_memory | default(qemu_vm_memory) }}", "path_disk": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.qcow2", "path_pid": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.pid", @@ -75,7 +75,7 @@ - name: Set hvf support set_fact: - qemu_host_capability_hvf: "{{ hv_support.stdout | trim == 'kern.hv_support: 1' }}" + qemu_cap_hvf: "{{ hv_support.stdout | trim == 'kern.hv_support: 1' }}" when: hv_support is defined ### prerequisites ######################################################### @@ -170,7 +170,7 @@ -bios {{ molecule_ephemeral_directory }}/run/QEMU_EFI.fd -cpu cortex-a72 -machine virt,highmem=off - {% if qemu_host_capability_hvf %} + {% if qemu_cap_hvf %} -accel hvf {% endif %} {% endif %} From ebec227c710e8193ace35986c8d970255d6234c5 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:19:29 +0400 Subject: [PATCH 12/13] add examples --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 64fe1bd..7174d58 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,15 @@ platforms: image_arch: aarch64 ssh_port: 10022 ssh_user: ubuntu + - name: ubuntu-2 + image: ~/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_arch: x86_64 # default - ssh_port: 10023 + ssh_port: 10024 ssh_user: debian provisioner: From de6341ca28f8e3a2ccb2a07dd3321ee41f57b163 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 26 May 2023 09:22:06 +0400 Subject: [PATCH 13/13] lint --- molecule_qemu/playbooks/create.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 161d41f..6637363 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -68,13 +68,13 @@ ### capabilities ########################################################## - name: Read kern.hv_support - command: sysctl kern.hv_support + ansible.builtin.command: sysctl kern.hv_support register: hv_support - changed_when: False - ignore_errors: True + changed_when: false + ignore_errors: true - name: Set hvf support - set_fact: + ansible.builtin.set_fact: qemu_cap_hvf: "{{ hv_support.stdout | trim == 'kern.hv_support: 1' }}" when: hv_support is defined @@ -95,6 +95,7 @@ ansible.builtin.get_url: url: "https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/QEMU_EFI.fd" dest: "{{ molecule_ephemeral_directory }}/run/QEMU_EFI.fd" + mode: "0644" when: "'aarch64' in molecule_instances | map(attribute='image_arch') | list | unique" ### cloud-init ############################################################