From 91a427f0fac6b78488e2a2d2ff9ddb64c7f68953 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:19:25 +0400 Subject: [PATCH 01/18] replace image with image_url --- molecule_qemu/playbooks/create.yml | 8 ++++---- tests/molecule/default/molecule.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 5e45734..52bbeca 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -30,9 +30,9 @@ "instance": "molecule-{{ molecule_project_name }}-{{ molecule_scenario_name }}-{{ item.name }}", "name": "{{ item.name }}", - "image": "{{ item.image }}", - "image_checksum": "{{ item.image_checksum | default(omit) }}", "image_arch": "{{ item.image_arch | default(qemu_vm_image_arch) }}", + "image_url": "{{ item.image_url }}", + "image_checksum": "{{ item.image_checksum | default(omit) }}", "image_format": "{{ item.image_format | default(qemu_vm_image_format) }}", "ssh_port": "{{ item.ssh_port | default(22) }}", @@ -152,7 +152,7 @@ checksum: "{{ item[1] }}" dest: "{{ molecule_driver_directory }}/images/{{ item[0] | basename }}" mode: "0644" - loop: "{{ molecule_instances | map(attribute='image') | zip(molecule_instances | map(attribute='image_checksum')) | list | unique }}" + loop: "{{ molecule_instances | map(attribute='image_url') | zip(molecule_instances | map(attribute='image_checksum')) | list | unique }}" loop_control: label: "{{ item[0] | basename }}" register: images @@ -218,7 +218,7 @@ ansible.builtin.command: > qemu-img create -f qcow2 - -o backing_file={{ images_cache[item.image] }},backing_fmt={{ item.image_format }} + -o backing_file={{ images_cache[item.image_url] }},backing_fmt={{ item.image_format }} {{ item.path_disk }} {{ item.vm_disk }} args: diff --git a/tests/molecule/default/molecule.yml b/tests/molecule/default/molecule.yml index b90f85f..b6bfbda 100644 --- a/tests/molecule/default/molecule.yml +++ b/tests/molecule/default/molecule.yml @@ -5,10 +5,10 @@ driver: name: molecule-qemu platforms: - name: debian-bullseye-arm64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 - image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS image_arch: aarch64 ssh_port: 2022 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 + image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS provisioner: name: ansible verifier: From 7547acb2d95de439be6d69817169d072f817754e Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:28:40 +0400 Subject: [PATCH 02/18] update vars names --- molecule_qemu/playbooks/create.yml | 58 +++++++++++++++-------------- tests/molecule/default/molecule.yml | 2 +- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 52bbeca..6c7d348 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -10,12 +10,15 @@ molecule_scenario_name: "{{ lookup('env', 'MOLECULE_SCENARIO_NAME') }}" molecule_project_name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}" qemu_cap_hvf: false - qemu_vm_image_arch: "x86_64" - qemu_vm_image_format: "qcow2" - qemu_vm_memory: "1024" - qemu_vm_cpus: "2" - qemu_vm_disk: "4G" - qemu_vm_network: "user" + + qemu_image_arch: "x86_64" + qemu_image_format: "qcow2" + + qemu_vm_memory: "512" + qemu_vm_cpus: "1" + qemu_vm_disk: "8G" + + qemu_network_mode: "user" environment: http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy') | default(omit) }}" @@ -30,19 +33,20 @@ "instance": "molecule-{{ molecule_project_name }}-{{ molecule_scenario_name }}-{{ item.name }}", "name": "{{ item.name }}", - "image_arch": "{{ item.image_arch | default(qemu_vm_image_arch) }}", + "image_arch": "{{ item.image_arch | default(qemu_image_arch) }}", "image_url": "{{ item.image_url }}", "image_checksum": "{{ item.image_checksum | default(omit) }}", - "image_format": "{{ item.image_format | default(qemu_vm_image_format) }}", + "image_format": "{{ item.image_format | default(qemu_image_format) }}", + + "network_mode": "{{ item.network_mode | default(qemu_network_mode) }}", + "network_mac": "{{ '52:54:00' | community.general.random_mac(seed=(molecule_project_name + molecule_scenario_name + item.name) | to_json | hash('md5')) | regex_replace('(^|:)0([0-9A-Fa-f])', '\\1\\2') }}", - "ssh_port": "{{ item.ssh_port | default(22) }}", - "ssh_user": "{{ item.ssh_user | default('root') }}", + "network_ssh_port": "{{ item.network_ssh_port | default(2222) }}", + "network_ssh_user": "{{ item.network_ssh_user | default('root') }}", "vm_cpus": "{{ item.vm_cpus | default(qemu_vm_cpus) }}", "vm_memory": "{{ item.vm_memory | default(qemu_vm_memory) }}", "vm_disk": "{{ item.vm_disk | default(qemu_vm_disk) }}", - "vm_network": "{{ item.vm_network | default(qemu_vm_network) }}", - "vm_network_mac": "{{ '52:54:00' | community.general.random_mac(seed=(molecule_project_name + molecule_scenario_name + item.name) | to_json | hash('md5')) | regex_replace('(^|:)0([0-9A-Fa-f])', '\\1\\2') }}", "path_disk": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.qcow2", "path_pid": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.pid", @@ -71,7 +75,7 @@ ansible.builtin.assert: that: - item.image_arch in ['x86_64', 'aarch64'] - - item.vm_network in ['user', 'vmnet-shared'] + - item.network_mode in ['user', 'vmnet-shared'] fail_msg: "Molecule instance {{ item.name }} configuration is not supported" success_msg: "Molecule instance {{ item.name }} configuration is supported" loop: "{{ molecule_instances }}" @@ -81,21 +85,21 @@ - name: Assert VMs network configuration ansible.builtin.assert: that: - - molecule_instances | map(attribute='vm_network') | list | unique | length == 1 + - molecule_instances | map(attribute='network_mode') | list | unique | length == 1 fail_msg: "Network modes are mutually exclusive" success_msg: "Network modes are configured properly" - name: Set QEMU network ansible.builtin.set_fact: - qemu_vm_network: "{{ molecule_instances | map(attribute='vm_network') | list | unique | first }}" + qemu_network_mode: "{{ molecule_instances | map(attribute='network_mode') | list | unique | first }}" - name: Assert VMs ssh configuration ansible.builtin.assert: that: - - molecule_instances | map(attribute='ssh_port') | list | unique | length == molecule_instances | length + - molecule_instances | map(attribute='network_ssh_port') | list | unique | length == molecule_instances | length fail_msg: "Molecule instances SSH are not properly configured for 'user' network" success_msg: "Molecule instances SSH are properly configured for 'user' network" - when: qemu_vm_network == 'user' + when: qemu_network_mode == 'user' ### capabilities ########################################################## @@ -229,7 +233,7 @@ - name: Launch VMs as priviliged user ansible.builtin.set_fact: - qemu_privileged: "{{ (qemu_vm_network == 'vmnet-shared') | bool }}" + qemu_privileged: "{{ (qemu_network_mode == 'vmnet-shared') | bool }}" - name: Launch VMs become: "{{ qemu_privileged }}" @@ -241,11 +245,11 @@ -hda {{ item.path_disk }} -m {{ item.vm_memory }} -smp {{ item.vm_cpus }} - {% if item.vm_network == 'vmnet-shared' %} - -nic vmnet-shared,model=virtio-net-pci,mac={{ item.vm_network_mac }} + {% if item.network_mode == 'vmnet-shared' %} + -nic vmnet-shared,model=virtio-net-pci,mac={{ item.network_mac }} {% endif %} - {% if item.vm_network == 'user' %} - -nic user,model=virtio-net-pci,hostfwd=tcp::{{ item.ssh_port }}-:22 + {% if item.network_mode == 'user' %} + -nic user,model=virtio-net-pci,hostfwd=tcp::{{ item.network_ssh_port }}-:22 {% endif %} -display none -daemonize @@ -289,12 +293,12 @@ ### qemu network: vmnet-shared ############################################ - name: Configure QEMU network (vmnet-shared) - when: qemu_vm_network == 'vmnet-shared' + when: qemu_network_mode == 'vmnet-shared' block: - name: Get IPv4 addresses from ARP table (vmnet-shared) ansible.builtin.shell: | set -o pipefail - arp -an | grep -i '{{ item.vm_network_mac }}' | awk '{print $2}' | sed 's/[()]//g' + arp -an | grep -i '{{ item.network_mac }}' | awk '{print $2}' | sed 's/[()]//g' until: molecule_instances_arp.stdout | length > 0 retries: 30 delay: 1 @@ -317,7 +321,7 @@ - name: Wait for SSH ansible.builtin.wait_for: host: "{{ molecule_instances_ipv4[item.name] }}" - port: "{{ item.ssh_port }}" + port: "{{ item.network_ssh_port }}" delay: 30 timeout: "{{ 600 * molecule_instances | length }}" search_regex: "OpenSSH" @@ -333,8 +337,8 @@ "instance": "{{ item.instance }}", "name": "{{ item.name }}", "address": "{{ molecule_instances_ipv4[item.name] }}", - "user": "{{ item.ssh_user }}", - "port": "{{ item.ssh_port }}", + "user": "{{ item.network_ssh_user }}", + "port": "{{ item.network_ssh_port }}", "identity_file": "{{ ssh_keypair.filename }}", "pidfile": "{{ item.path_pid }}", "diskfile": "{{ item.path_disk }}", diff --git a/tests/molecule/default/molecule.yml b/tests/molecule/default/molecule.yml index b6bfbda..90087b7 100644 --- a/tests/molecule/default/molecule.yml +++ b/tests/molecule/default/molecule.yml @@ -6,9 +6,9 @@ driver: platforms: - name: debian-bullseye-arm64 image_arch: aarch64 - ssh_port: 2022 image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS + provisioner: name: ansible verifier: From 1660cf8267a95ae906eaf08ef81fd46f6fcebd89 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:32:16 +0400 Subject: [PATCH 03/18] update tests configuration --- tests/molecule/network-shared/molecule.yml | 11 +++++------ tests/molecule/network-user/molecule.yml | 10 ++++------ tests/molecule/os-debian-bullseye/molecule.yml | 10 ++++------ tests/molecule/os-ubuntu-focal/molecule.yml | 10 ++++------ tests/molecule/os-ubuntu-jammy/molecule.yml | 10 ++++------ tests/molecule/platform-amd64/molecule.yml | 4 +--- tests/molecule/platform-arm64/molecule.yml | 5 ++--- 7 files changed, 24 insertions(+), 36 deletions(-) diff --git a/tests/molecule/network-shared/molecule.yml b/tests/molecule/network-shared/molecule.yml index 1e3d3ce..b326e27 100644 --- a/tests/molecule/network-shared/molecule.yml +++ b/tests/molecule/network-shared/molecule.yml @@ -5,15 +5,14 @@ driver: name: molecule-qemu platforms: - name: debian-bullseye-amd64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS - image_arch: x86_64 - vm_network: vmnet-shared + network_mode: vmnet-shared - name: debian-bullseye-arm64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 - image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS image_arch: aarch64 - vm_network: vmnet-shared + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 + image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS + network_mode: vmnet-shared provisioner: name: ansible verifier: diff --git a/tests/molecule/network-user/molecule.yml b/tests/molecule/network-user/molecule.yml index 27d0757..e2ce872 100644 --- a/tests/molecule/network-user/molecule.yml +++ b/tests/molecule/network-user/molecule.yml @@ -5,15 +5,13 @@ driver: name: molecule-qemu platforms: - name: debian-bullseye-amd64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS - image_arch: x86_64 - ssh_port: 10000 - name: debian-bullseye-arm64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 - image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS image_arch: aarch64 - ssh_port: 10001 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 + image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS + network_ssh_port: 2223 provisioner: name: ansible verifier: diff --git a/tests/molecule/os-debian-bullseye/molecule.yml b/tests/molecule/os-debian-bullseye/molecule.yml index 27d0757..e2ce872 100644 --- a/tests/molecule/os-debian-bullseye/molecule.yml +++ b/tests/molecule/os-debian-bullseye/molecule.yml @@ -5,15 +5,13 @@ driver: name: molecule-qemu platforms: - name: debian-bullseye-amd64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS - image_arch: x86_64 - ssh_port: 10000 - name: debian-bullseye-arm64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 - image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS image_arch: aarch64 - ssh_port: 10001 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 + image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS + network_ssh_port: 2223 provisioner: name: ansible verifier: diff --git a/tests/molecule/os-ubuntu-focal/molecule.yml b/tests/molecule/os-ubuntu-focal/molecule.yml index 3c06a7f..ee75b3f 100644 --- a/tests/molecule/os-ubuntu-focal/molecule.yml +++ b/tests/molecule/os-ubuntu-focal/molecule.yml @@ -5,15 +5,13 @@ driver: name: molecule-qemu platforms: - name: ubuntu-focal-amd64 - image: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img + image_url: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img image_checksum: sha256:https://cloud-images.ubuntu.com/focal/current/SHA256SUMS - image_arch: x86_64 - ssh_port: 10000 - name: ubuntu-focal-arm64 - image: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-arm64.img - image_checksum: sha256:https://cloud-images.ubuntu.com/focal/current/SHA256SUMS image_arch: aarch64 - ssh_port: 10001 + image_url: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-arm64.img + image_checksum: sha256:https://cloud-images.ubuntu.com/focal/current/SHA256SUMS + network_ssh_port: 2223 provisioner: name: ansible verifier: diff --git a/tests/molecule/os-ubuntu-jammy/molecule.yml b/tests/molecule/os-ubuntu-jammy/molecule.yml index 2f204ce..9887466 100644 --- a/tests/molecule/os-ubuntu-jammy/molecule.yml +++ b/tests/molecule/os-ubuntu-jammy/molecule.yml @@ -5,15 +5,13 @@ driver: name: molecule-qemu platforms: - name: ubuntu-jammy-amd64 - image: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img + image_url: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img image_checksum: sha256:https://cloud-images.ubuntu.com/jammy/current/SHA256SUMS - image_arch: x86_64 - ssh_port: 10000 - name: ubuntu-jammy-arm64 - image: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-arm64.img - image_checksum: sha256:https://cloud-images.ubuntu.com/jammy/current/SHA256SUMS image_arch: aarch64 - ssh_port: 10001 + image_url: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-arm64.img + image_checksum: sha256:https://cloud-images.ubuntu.com/jammy/current/SHA256SUMS + network_ssh_port: 2223 provisioner: name: ansible verifier: diff --git a/tests/molecule/platform-amd64/molecule.yml b/tests/molecule/platform-amd64/molecule.yml index 353003b..88a792d 100644 --- a/tests/molecule/platform-amd64/molecule.yml +++ b/tests/molecule/platform-amd64/molecule.yml @@ -5,10 +5,8 @@ driver: name: molecule-qemu platforms: - name: debian-bullseye-amd64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS - image_arch: x86_64 - ssh_port: 2022 provisioner: name: ansible verifier: diff --git a/tests/molecule/platform-arm64/molecule.yml b/tests/molecule/platform-arm64/molecule.yml index b90f85f..07ad9e5 100644 --- a/tests/molecule/platform-arm64/molecule.yml +++ b/tests/molecule/platform-arm64/molecule.yml @@ -5,10 +5,9 @@ driver: name: molecule-qemu platforms: - name: debian-bullseye-arm64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 - image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS image_arch: aarch64 - ssh_port: 2022 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 + image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS provisioner: name: ansible verifier: From 8426024b20c278fe421262136a24def3a531c761 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:42:18 +0400 Subject: [PATCH 04/18] update docs --- README.md | 77 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index dbe47df..f682044 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ driver: name: molecule-qemu platforms: - name: debian-bullseye-arm64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS image_arch: aarch64 vm_network: vmnet-shared @@ -53,6 +53,25 @@ verifier: name: testinfra ``` +Full list of supported options: +```yaml +platforms: + - name: debian-bullseye-arm64 + + image_arch: aarch64 # optional, default is x86_64 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 + image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS + image_format: qcow2 # optional, default is qcow2 + + network_mode: vmnet-shared # optional, default is user + network_ssh_port: 10000 # optional, default is 2222 + network_ssh_user: root # optional, default is root + + vm_cpus: 1 # optional, default is 1 + vm_memory: 512 # optional, default is 512 + vm_disk: 8G # optional, default is 8G +``` + ### Dependencies Install QEMU and CDRTools on macOS: @@ -77,11 +96,11 @@ Mode is selected by setting `vm_network: user` in `molecule.yml`. This is the de ```yaml - name: debian-bullseye-arm64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 - image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS image_arch: aarch64 - vm_network: user # this is the default - ssh_port: 2022 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 + image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS + network_mode: user + network_ssh_port: 2222 ``` ### `vmnet-shared` network mode @@ -92,9 +111,9 @@ Mode is selected by setting `vm_network: vmnet-shared` in `molecule.yml`. Exampl ```yaml - name: debian-bullseye-arm64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 - image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS image_arch: aarch64 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 + image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS vm_network: vmnet-shared ``` @@ -106,36 +125,38 @@ See [tests](https://github.com/andreygubarev/molecule-qemu/tree/main/tests/molec ```yaml platforms: - - name: debian-bullseye-arm64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 + + - name: debian-bullseye-amd64 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS + + - name: debian-bullseye-arm64 image_arch: aarch64 - ssh_port: 10000 - - name: debian-bullseye-amd64 - image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 + image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS - image_arch: x86_64 - ssh_port: 10001 - - name: ubuntu-focal-arm64 - image: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-arm64.img + network_ssh_port: 2223 + + - name: ubuntu-focal-amd64 + image_url: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img image_checksum: sha256:https://cloud-images.ubuntu.com/focal/current/SHA256SUMS + network_ssh_port: 2224 + + - name: ubuntu-focal-arm64 image_arch: aarch64 - ssh_port: 10002 - - name: ubuntu-focal-amd64 - image: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img + image_url: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-arm64.img image_checksum: sha256:https://cloud-images.ubuntu.com/focal/current/SHA256SUMS - image_arch: x86_64 - ssh_port: 10003 - - name: ubuntu-jammy-arm64 - image: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-arm64.img + network_ssh_port: 2225 + + - name: ubuntu-jammy-amd64 + image_url: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img image_checksum: sha256:https://cloud-images.ubuntu.com/jammy/current/SHA256SUMS + network_ssh_port: 2226 + +- name: ubuntu-jammy-arm64 image_arch: aarch64 - ssh_port: 10004 - - name: ubuntu-jammy-amd64 - image: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img + image_url: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-arm64.img image_checksum: sha256:https://cloud-images.ubuntu.com/jammy/current/SHA256SUMS - image_arch: x86_64 - ssh_port: 10005 + network_ssh_port: 2227 ``` # Cloud Images URLs From 426e1a17d68f4999950ca810ded840f04e2f1d1a Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:43:05 +0400 Subject: [PATCH 05/18] fix docs --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f682044..4638a40 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ apt-get install mkisofs qemu-system-x86 qemu-utils This is the default network mode. It uses QEMU's user networking mode. -Mode is selected by setting `vm_network: user` in `molecule.yml`. This is the default mode. SSH port is forwarded to the host and must be unique for each platform (use `ssh_port` option to set it). Example: +Mode is selected by setting `network_mode: user` in `molecule.yml`. This is the default mode. SSH port is forwarded to the host and must be unique for each platform (use `network_ssh_port` option to set it). Example: ```yaml - name: debian-bullseye-arm64 @@ -107,14 +107,14 @@ Mode is selected by setting `vm_network: user` in `molecule.yml`. This is the de This mode uses QEMU's `vmnet-shared` networking mode. It requires `vmnet.framework` to be installed on the host. This mode is only supported on MacOS. It requires *passwordless* `sudo` access for current user. -Mode is selected by setting `vm_network: vmnet-shared` in `molecule.yml`. Example: +Mode is selected by setting `network_mode: vmnet-shared` in `molecule.yml`. Example: ```yaml - name: debian-bullseye-arm64 image_arch: aarch64 image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS - vm_network: vmnet-shared + network_mode: vmnet-shared ``` # Examples From a8b86bdeda94b95f0c5a9fc0105faa13e70e9a5c Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:43:44 +0400 Subject: [PATCH 06/18] fix example --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4638a40..9bf57ad 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,10 @@ driver: name: molecule-qemu platforms: - name: debian-bullseye-arm64 + image_arch: aarch64 image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS - image_arch: aarch64 - vm_network: vmnet-shared + network_mode: vmnet-shared provisioner: name: ansible inventory: From a8f365724a36ba1c5fb6d52870377325b332dfe7 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:45:09 +0400 Subject: [PATCH 07/18] remove empty line --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 9bf57ad..181ba02 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,6 @@ For convenience, here are the URLs for the cloud images used in the examples abo * https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img - # Reference * [Ansible](https://www.ansible.com/) From a14f011678a47bf698c6a37b296d888f2e6ecbbf Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:46:58 +0400 Subject: [PATCH 08/18] max timeout for ssh port is 600 --- 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 6c7d348..e7ea9d0 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -323,7 +323,7 @@ host: "{{ molecule_instances_ipv4[item.name] }}" port: "{{ item.network_ssh_port }}" delay: 30 - timeout: "{{ 600 * molecule_instances | length }}" + timeout: 600 search_regex: "OpenSSH" loop: "{{ molecule_instances }}" loop_control: From f896112ce45d5e9e77b74f08472abcc512d6f4e9 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:56:01 +0400 Subject: [PATCH 09/18] fix readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 181ba02..3d69b82 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,11 @@ platforms: network_ssh_port: 2227 ``` +# Troubleshooting + +Molecule working directory is: `~/.cache/molecule//`. +QEMU images caches is: `~/.cache/molecule/.qemu`. + # Cloud Images URLs For convenience, here are the URLs for the cloud images used in the examples above. From 16d462c626c27a3ef03ba2d73605448ea7639c07 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:56:21 +0400 Subject: [PATCH 10/18] increase resources for amd64 in network shared mode --- tests/molecule/network-shared/molecule.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/molecule/network-shared/molecule.yml b/tests/molecule/network-shared/molecule.yml index b326e27..862435a 100644 --- a/tests/molecule/network-shared/molecule.yml +++ b/tests/molecule/network-shared/molecule.yml @@ -8,6 +8,8 @@ platforms: image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS network_mode: vmnet-shared + vm_memory: 2048 + vm_cpus: 2 - name: debian-bullseye-arm64 image_arch: aarch64 image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 From 6365b36a78cf22d9600893cff39fe66980a5afec Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:56:36 +0400 Subject: [PATCH 11/18] randomize mac addressess --- 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 e7ea9d0..dff02cf 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -39,7 +39,7 @@ "image_format": "{{ item.image_format | default(qemu_image_format) }}", "network_mode": "{{ item.network_mode | default(qemu_network_mode) }}", - "network_mac": "{{ '52:54:00' | community.general.random_mac(seed=(molecule_project_name + molecule_scenario_name + item.name) | to_json | hash('md5')) | regex_replace('(^|:)0([0-9A-Fa-f])', '\\1\\2') }}", + "network_mac": "{{ '52:54:00' | community.general.random_mac() | regex_replace('(^|:)0([0-9A-Fa-f])', '\\1\\2') }}", "network_ssh_port": "{{ item.network_ssh_port | default(2222) }}", "network_ssh_user": "{{ item.network_ssh_user | default('root') }}", From 95dc2b5c2595ae0b6b776c19639438babd4126a9 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:56:43 +0400 Subject: [PATCH 12/18] wait for arp cache for longer --- 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 dff02cf..2e7e38e 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -300,7 +300,7 @@ set -o pipefail arp -an | grep -i '{{ item.network_mac }}' | awk '{print $2}' | sed 's/[()]//g' until: molecule_instances_arp.stdout | length > 0 - retries: 30 + retries: 60 delay: 1 loop: "{{ molecule_instances }}" loop_control: From 577494dcfcd29553164da77d1c2a5faa6df49d7f Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:57:57 +0400 Subject: [PATCH 13/18] increase timeout for arp --- 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 2e7e38e..4973148 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -300,7 +300,7 @@ set -o pipefail arp -an | grep -i '{{ item.network_mac }}' | awk '{print $2}' | sed 's/[()]//g' until: molecule_instances_arp.stdout | length > 0 - retries: 60 + retries: 120 delay: 1 loop: "{{ molecule_instances }}" loop_control: From b09c75f8179a99b6bde26e3d23a747e245506618 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 13:59:21 +0400 Subject: [PATCH 14/18] add configurable timeouts --- molecule_qemu/playbooks/create.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 4973148..8abc0a6 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -10,15 +10,14 @@ molecule_scenario_name: "{{ lookup('env', 'MOLECULE_SCENARIO_NAME') }}" molecule_project_name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}" qemu_cap_hvf: false - qemu_image_arch: "x86_64" qemu_image_format: "qcow2" - qemu_vm_memory: "512" qemu_vm_cpus: "1" qemu_vm_disk: "8G" - qemu_network_mode: "user" + qemu_timeout_arp: 120 + qemu_timeout_ssh: 600 environment: http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy') | default(omit) }}" @@ -300,7 +299,7 @@ set -o pipefail arp -an | grep -i '{{ item.network_mac }}' | awk '{print $2}' | sed 's/[()]//g' until: molecule_instances_arp.stdout | length > 0 - retries: 120 + retries: "{{ qemu_timeout_arp }}" delay: 1 loop: "{{ molecule_instances }}" loop_control: @@ -323,7 +322,7 @@ host: "{{ molecule_instances_ipv4[item.name] }}" port: "{{ item.network_ssh_port }}" delay: 30 - timeout: 600 + timeout: "{{ qemu_timeout_ssh }}" search_regex: "OpenSSH" loop: "{{ molecule_instances }}" loop_control: From 51b333f92a25017b6e4b60680ac4fcd6cc6e8771 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 14:05:24 +0400 Subject: [PATCH 15/18] use default 22 as port --- 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 8abc0a6..d8f384a 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -40,7 +40,7 @@ "network_mode": "{{ item.network_mode | default(qemu_network_mode) }}", "network_mac": "{{ '52:54:00' | community.general.random_mac() | regex_replace('(^|:)0([0-9A-Fa-f])', '\\1\\2') }}", - "network_ssh_port": "{{ item.network_ssh_port | default(2222) }}", + "network_ssh_port": "{{ item.network_ssh_port | default(22) }}", "network_ssh_user": "{{ item.network_ssh_user | default('root') }}", "vm_cpus": "{{ item.vm_cpus | default(qemu_vm_cpus) }}", From 43afe5e378b0cc27ddab737b8c364d14fc5b129e Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 14:09:53 +0400 Subject: [PATCH 16/18] add default port for user mode --- tests/molecule/default/molecule.yml | 2 +- tests/molecule/network-user/molecule.yml | 1 + tests/molecule/os-debian-bullseye/molecule.yml | 1 + tests/molecule/os-ubuntu-focal/molecule.yml | 1 + tests/molecule/os-ubuntu-jammy/molecule.yml | 1 + tests/molecule/platform-amd64/molecule.yml | 1 + tests/molecule/platform-arm64/molecule.yml | 1 + 7 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/molecule/default/molecule.yml b/tests/molecule/default/molecule.yml index 90087b7..ef4e544 100644 --- a/tests/molecule/default/molecule.yml +++ b/tests/molecule/default/molecule.yml @@ -8,7 +8,7 @@ platforms: image_arch: aarch64 image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS - + network_ssh_port: 2222 provisioner: name: ansible verifier: diff --git a/tests/molecule/network-user/molecule.yml b/tests/molecule/network-user/molecule.yml index e2ce872..be7a949 100644 --- a/tests/molecule/network-user/molecule.yml +++ b/tests/molecule/network-user/molecule.yml @@ -7,6 +7,7 @@ platforms: - name: debian-bullseye-amd64 image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS + network_ssh_port: 2222 - name: debian-bullseye-arm64 image_arch: aarch64 image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 diff --git a/tests/molecule/os-debian-bullseye/molecule.yml b/tests/molecule/os-debian-bullseye/molecule.yml index e2ce872..be7a949 100644 --- a/tests/molecule/os-debian-bullseye/molecule.yml +++ b/tests/molecule/os-debian-bullseye/molecule.yml @@ -7,6 +7,7 @@ platforms: - name: debian-bullseye-amd64 image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS + network_ssh_port: 2222 - name: debian-bullseye-arm64 image_arch: aarch64 image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 diff --git a/tests/molecule/os-ubuntu-focal/molecule.yml b/tests/molecule/os-ubuntu-focal/molecule.yml index ee75b3f..444479f 100644 --- a/tests/molecule/os-ubuntu-focal/molecule.yml +++ b/tests/molecule/os-ubuntu-focal/molecule.yml @@ -7,6 +7,7 @@ platforms: - name: ubuntu-focal-amd64 image_url: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img image_checksum: sha256:https://cloud-images.ubuntu.com/focal/current/SHA256SUMS + network_ssh_port: 2222 - name: ubuntu-focal-arm64 image_arch: aarch64 image_url: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-arm64.img diff --git a/tests/molecule/os-ubuntu-jammy/molecule.yml b/tests/molecule/os-ubuntu-jammy/molecule.yml index 9887466..0152a96 100644 --- a/tests/molecule/os-ubuntu-jammy/molecule.yml +++ b/tests/molecule/os-ubuntu-jammy/molecule.yml @@ -7,6 +7,7 @@ platforms: - name: ubuntu-jammy-amd64 image_url: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img image_checksum: sha256:https://cloud-images.ubuntu.com/jammy/current/SHA256SUMS + network_ssh_port: 2222 - name: ubuntu-jammy-arm64 image_arch: aarch64 image_url: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-arm64.img diff --git a/tests/molecule/platform-amd64/molecule.yml b/tests/molecule/platform-amd64/molecule.yml index 88a792d..033c72a 100644 --- a/tests/molecule/platform-amd64/molecule.yml +++ b/tests/molecule/platform-amd64/molecule.yml @@ -7,6 +7,7 @@ platforms: - name: debian-bullseye-amd64 image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS + network_ssh_port: 2222 provisioner: name: ansible verifier: diff --git a/tests/molecule/platform-arm64/molecule.yml b/tests/molecule/platform-arm64/molecule.yml index 07ad9e5..ef4e544 100644 --- a/tests/molecule/platform-arm64/molecule.yml +++ b/tests/molecule/platform-arm64/molecule.yml @@ -8,6 +8,7 @@ platforms: image_arch: aarch64 image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS + network_ssh_port: 2222 provisioner: name: ansible verifier: From e421205b921961b047b815cdbd110bc4ffade78d Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 14:16:35 +0400 Subject: [PATCH 17/18] fix readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d69b82..4afbe1d 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ platforms: image_format: qcow2 # optional, default is qcow2 network_mode: vmnet-shared # optional, default is user - network_ssh_port: 10000 # optional, default is 2222 + network_ssh_port: 2222 # optional, default is 22 network_ssh_user: root # optional, default is root vm_cpus: 1 # optional, default is 1 @@ -129,6 +129,7 @@ platforms: - name: debian-bullseye-amd64 image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS + network_ssh_port: 2222 - name: debian-bullseye-arm64 image_arch: aarch64 From 6c168ccfc0e664cf48e43e94cd623f51d15e112b Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Sat, 17 Jun 2023 14:19:09 +0400 Subject: [PATCH 18/18] add deps --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4afbe1d..137d402 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,10 @@ platforms: ### Dependencies +Driver depends on: +* QEMU (tested with 8.0.2) +* mkisofs (tested with 3.02a09) + Install QEMU and CDRTools on macOS: ```bash