From fbc7b37f2beb7d85a14752843071a4894574bb1e Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 19:50:08 +0400 Subject: [PATCH 01/33] use -nic argument --- molecule_qemu/playbooks/create.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 22a7ffc..bbeb578 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -205,8 +205,7 @@ -hda {{ item.path_disk }} -m {{ item.vm_memory }} -smp {{ item.vm_cpus }} - -net nic - -net user,hostfwd=tcp::{{ item.ssh_port }}-:22 + -nic user,hostfwd=tcp::{{ item.ssh_port }}-:22 -display none -daemonize -pidfile {{ item.path_pid }} From 743bd639deb513a135cae52d7112d62ca463a82d Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 19:53:35 +0400 Subject: [PATCH 02/33] remove extra spaces --- 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 bbeb578..58f876f 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -197,7 +197,7 @@ label: "{{ item.name }}" - name: Launch VMs - ansible.builtin.command: > + ansible.builtin.command: >- qemu-system-{{ item.image_arch }} -name {{ item.name }} -boot d From d4916f36e627184a61bb4c9399ae12bd29dd06df Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 20:01:16 +0400 Subject: [PATCH 03/33] add vmnet-shared support --- molecule_qemu/playbooks/create.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 58f876f..52e19bc 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -15,6 +15,7 @@ qemu_vm_memory: "1024" qemu_vm_cpus: "2" qemu_vm_disk: "4G" + qemu_vm_network: "shared" tasks: ### configuration ######################################################### @@ -205,7 +206,12 @@ -hda {{ item.path_disk }} -m {{ item.vm_memory }} -smp {{ item.vm_cpus }} + {% if qemu_vm_network == 'shared' %} + -nic vmnet-shared,model=virtio-net-device,mac={{ '52:54:00' | community.general.random_mac(seed=item.name) }} + {% endif %} + {% if qemu_vm_network == 'user' %} -nic user,hostfwd=tcp::{{ item.ssh_port }}-:22 + {% endif %} -display none -daemonize -pidfile {{ item.path_pid }} From 7b72bedfd3623b5662b221338df914355a34f8f2 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 20:06:17 +0400 Subject: [PATCH 04/33] update support device --- 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 52e19bc..2c57409 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -207,7 +207,7 @@ -m {{ item.vm_memory }} -smp {{ item.vm_cpus }} {% if qemu_vm_network == 'shared' %} - -nic vmnet-shared,model=virtio-net-device,mac={{ '52:54:00' | community.general.random_mac(seed=item.name) }} + -nic vmnet-shared,model=virtio-net-pci,mac={{ '52:54:00' | community.general.random_mac(seed=item.name) }} {% endif %} {% if qemu_vm_network == 'user' %} -nic user,hostfwd=tcp::{{ item.ssh_port }}-:22 From 7c912abbceac6c6dc053a9a916a7c7c9b0077d50 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 20:06:36 +0400 Subject: [PATCH 05/33] user mode by default for network --- 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 2c57409..96d2415 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -15,7 +15,7 @@ qemu_vm_memory: "1024" qemu_vm_cpus: "2" qemu_vm_disk: "4G" - qemu_vm_network: "shared" + qemu_vm_network: "user" tasks: ### configuration ######################################################### From 7fa733b33b7665b8a42fdee988b721ccb2f0840a Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 20:44:55 +0400 Subject: [PATCH 06/33] add network config validation --- 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 96d2415..5f4543e 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -37,6 +37,7 @@ "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) }}", "path_disk": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.qcow2", "path_pid": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.pid", @@ -65,6 +66,7 @@ ansible.builtin.assert: that: - item.image_arch in ['x86_64', 'aarch64'] + - item.vm_network 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 }}" @@ -206,10 +208,10 @@ -hda {{ item.path_disk }} -m {{ item.vm_memory }} -smp {{ item.vm_cpus }} - {% if qemu_vm_network == 'shared' %} + {% if item.vm_network == 'vmnet-shared' %} -nic vmnet-shared,model=virtio-net-pci,mac={{ '52:54:00' | community.general.random_mac(seed=item.name) }} {% endif %} - {% if qemu_vm_network == 'user' %} + {% if item.vm_network == 'user' %} -nic user,hostfwd=tcp::{{ item.ssh_port }}-:22 {% endif %} -display none From b76a60bde0644949e2bb4f4f1b95e4d6c57c564a Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 20:51:16 +0400 Subject: [PATCH 07/33] generate mac for every vm --- 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 5f4543e..195859b 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -38,6 +38,7 @@ "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=item.name) }}", "path_disk": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.qcow2", "path_pid": "{{ molecule_ephemeral_directory }}/run/{{ item.name }}.pid", From 967c52d42cb4c7605c94067cedc8c11ef1c28866 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 21:07:29 +0400 Subject: [PATCH 08/33] generate shorten mac to match arp -an output --- 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 195859b..3186fd6 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -38,7 +38,7 @@ "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=item.name) }}", + "vm_network_mac": "{{ '52:54:00' | community.general.random_mac(seed=item.name) | 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", @@ -210,7 +210,7 @@ -m {{ item.vm_memory }} -smp {{ item.vm_cpus }} {% if item.vm_network == 'vmnet-shared' %} - -nic vmnet-shared,model=virtio-net-pci,mac={{ '52:54:00' | community.general.random_mac(seed=item.name) }} + -nic vmnet-shared,model=virtio-net-pci,mac={{ item.vm_network_mac }} {% endif %} {% if item.vm_network == 'user' %} -nic user,hostfwd=tcp::{{ item.ssh_port }}-:22 From 5c940dc5c8a0617ad4ae4dfb6ec09431bdcb4739 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 21:38:07 +0400 Subject: [PATCH 09/33] add ipv4 discovery using arp cache --- molecule_qemu/playbooks/create.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 3186fd6..89dc29c 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -232,6 +232,26 @@ loop_control: label: "{{ item.name }}" + - name: Pause for 15 seconds + ansible.builtin.pause: + seconds: 15 + + - name: Set VMs IPv4 + ansible.builtin.shell: >- + arp -an + | grep -i '{{ item.vm_network_mac }}' + | awk '{print $2}' + | sed 's/[()]//g' + loop: "{{ molecule_instances }}" + loop_control: + label: "{{ item.name }}" + register: molecule_instances_ipv4 + + - name: Create mapping for instances IPv4 + ansible.builtin.set_fact: + molecule_instances_ipv4: "{{ molecule_instances_ipv4.results | map(attribute='stdout') | list | zip(molecule_instances | map(attribute='name') | list) }}" + register: molecule_instances_ipv4 + ### ssh ################################################################### - name: Wait for SSH ansible.builtin.wait_for: From de687bb0ca9debe83e945d53cfbe4e9bb916f667 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 21:53:01 +0400 Subject: [PATCH 10/33] poll arp cache for ip addr --- molecule_qemu/playbooks/create.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 89dc29c..707ce10 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -232,16 +232,12 @@ loop_control: label: "{{ item.name }}" - - name: Pause for 15 seconds - ansible.builtin.pause: - seconds: 15 - - name: Set VMs IPv4 ansible.builtin.shell: >- - arp -an - | grep -i '{{ item.vm_network_mac }}' - | awk '{print $2}' - | sed 's/[()]//g' + arp -an | grep -i '{{ item.vm_network_mac }}' | awk '{print $2}' | sed 's/[()]//g' + until: molecule_instances_ipv4.stdout | length > 0 + retries: 30 + delay: 1 loop: "{{ molecule_instances }}" loop_control: label: "{{ item.name }}" From f31d87091658eefd89fc7415c66093e0e2b1cba4 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:01:12 +0400 Subject: [PATCH 11/33] update mapping --- molecule_qemu/playbooks/create.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 707ce10..ead519e 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -245,8 +245,7 @@ - name: Create mapping for instances IPv4 ansible.builtin.set_fact: - molecule_instances_ipv4: "{{ molecule_instances_ipv4.results | map(attribute='stdout') | list | zip(molecule_instances | map(attribute='name') | list) }}" - register: molecule_instances_ipv4 + molecule_instances_ipv4: "{{ molecule_instances | map(attribute='name') | list | zip(molecule_instances_ipv4.results | map(attribute='stdout') | list) }}" ### ssh ################################################################### - name: Wait for SSH From 860141fa8e2a9e2fe24c44c59924617aeb81c5b8 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:07:44 +0400 Subject: [PATCH 12/33] update default ssh 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 ead519e..18618f3 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -31,7 +31,7 @@ "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_port": "{{ item.ssh_port | default(22) }}", "ssh_user": "{{ item.ssh_user }}", "vm_cpus": "{{ item.vm_cpus | default(qemu_vm_cpus) }}", From 0d0d4883747aebbc63d30dde2e83e8b870785801 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:08:07 +0400 Subject: [PATCH 13/33] add empty lines to beautify --- molecule_qemu/playbooks/create.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 18618f3..be8bdc0 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -19,6 +19,7 @@ tasks: ### configuration ######################################################### + - name: Register VMs data ansible.builtin.set_fact: instance: { @@ -53,6 +54,7 @@ molecule_instances: "{{ molecule_instances.results | map(attribute='ansible_facts.instance') | list }}" ### assertions ############################################################ + - name: Assert VMs configuration ansible.builtin.assert: that: @@ -75,6 +77,7 @@ label: "{{ item.name }}" ### capabilities ########################################################## + - name: Read kern.hv_support ansible.builtin.command: sysctl kern.hv_support register: hv_support From fcc6ed80b4d35bcdb6bcb0db43b3aaec2401a996 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:08:28 +0400 Subject: [PATCH 14/33] make sure all the networks of vms are the same kind --- 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 be8bdc0..63ccc2b 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -62,6 +62,7 @@ - molecule_instances | length > 0 - molecule_instances | length == molecule_yml.platforms | length - molecule_instances | map(attribute='ssh_port') | list | unique | length == molecule_instances | length + - molecule_instances | map(attribute='vm_network') | list | unique | length == 1 fail_msg: "Molecule instances are not properly defined" success_msg: "Molecule instances are properly defined" From 20b91adc1695aa8aec5b799a8021ec461d7977f3 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:09:34 +0400 Subject: [PATCH 15/33] update assertions for network --- molecule_qemu/playbooks/create.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 63ccc2b..765c4e3 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -62,10 +62,16 @@ - molecule_instances | length > 0 - molecule_instances | length == molecule_yml.platforms | length - molecule_instances | map(attribute='ssh_port') | list | unique | length == molecule_instances | length - - molecule_instances | map(attribute='vm_network') | list | unique | length == 1 fail_msg: "Molecule instances are not properly defined" success_msg: "Molecule instances are properly defined" + - name: Assert VMs network configuration + ansible.builtin.assert: + that: + - molecule_instances | map(attribute='vm_network') | list | unique | length == 1 + fail_msg: "Molecule instances are not the same network" + success_msg: "Molecule instances networks are properly defined" + - name: Assert supported VMs configuration ansible.builtin.assert: that: From 7ae48d3ac3bc0acf40cc30ac8412a28ba4607321 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:11:43 +0400 Subject: [PATCH 16/33] update assertion for networks --- 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 765c4e3..e3838c4 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -65,13 +65,6 @@ fail_msg: "Molecule instances are not properly defined" success_msg: "Molecule instances are properly defined" - - name: Assert VMs network configuration - ansible.builtin.assert: - that: - - molecule_instances | map(attribute='vm_network') | list | unique | length == 1 - fail_msg: "Molecule instances are not the same network" - success_msg: "Molecule instances networks are properly defined" - - name: Assert supported VMs configuration ansible.builtin.assert: that: @@ -83,6 +76,17 @@ loop_control: label: "{{ item.name }}" + - name: Assert VMs network configuration + ansible.builtin.assert: + that: + - molecule_instances | map(attribute='vm_network') | list | unique | length == 1 + fail_msg: "Molecule instances are not the same network" + success_msg: "Molecule instances networks are properly defined" + + - name: Set QEMU network + ansible.builtin.set_fact: + qemu_vm_network: "{{ molecule_instances | map(attribute='vm_network') | list | unique | first }}" + ### capabilities ########################################################## - name: Read kern.hv_support From df1405b623670e01995605b817b86ef17959d530 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:12:02 +0400 Subject: [PATCH 17/33] update with empty lines --- molecule_qemu/playbooks/create.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index e3838c4..7a141e3 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -129,6 +129,7 @@ when: "'aarch64' in molecule_instances | map(attribute='image_arch') | list | unique" ### images ############################################################### + - name: Create images directory ansible.builtin.file: path: "{{ molecule_driver_directory }}/images/" @@ -159,6 +160,7 @@ label: "{{ item[0] | basename }}" ### cloud-init ############################################################ + - name: Create cloud-init folders ansible.builtin.file: path: "{{ molecule_ephemeral_directory }}/run/cloud-init/{{ item.name }}/" @@ -201,6 +203,7 @@ label: "{{ item.name }}" ### qemu ################################################################## + - name: Create VMs disks ansible.builtin.command: > qemu-img create @@ -262,6 +265,7 @@ molecule_instances_ipv4: "{{ molecule_instances | map(attribute='name') | list | zip(molecule_instances_ipv4.results | map(attribute='stdout') | list) }}" ### ssh ################################################################### + - name: Wait for SSH ansible.builtin.wait_for: host: "{{ item.ssh_host }}" @@ -288,6 +292,7 @@ delay: 10 ### molecule ############################################################## + - name: Prepare VMs config dict ansible.builtin.set_fact: instance_conf_dict: { From eccb7c2c1a2c0c2c13c7776c8b96b4359d0773bd Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:15:26 +0400 Subject: [PATCH 18/33] add ipv4 processing for vmnet-shared --- molecule_qemu/playbooks/create.yml | 42 ++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 7a141e3..77952d0 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -249,20 +249,34 @@ loop_control: label: "{{ item.name }}" - - name: Set VMs IPv4 - ansible.builtin.shell: >- - arp -an | grep -i '{{ item.vm_network_mac }}' | awk '{print $2}' | sed 's/[()]//g' - until: molecule_instances_ipv4.stdout | length > 0 - retries: 30 - delay: 1 - loop: "{{ molecule_instances }}" - loop_control: - label: "{{ item.name }}" - register: molecule_instances_ipv4 - - - name: Create mapping for instances IPv4 - ansible.builtin.set_fact: - molecule_instances_ipv4: "{{ molecule_instances | map(attribute='name') | list | zip(molecule_instances_ipv4.results | map(attribute='stdout') | list) }}" + ### qemu network: vmnet-shared ############################################ + + - name: Configure QEMU network (vmnet-shared) + block: + - name: Set VMs IPv4 + ansible.builtin.shell: >- + arp -an | grep -i '{{ item.vm_network_mac }}' | awk '{print $2}' | sed 's/[()]//g' + until: molecule_instances_ipv4_output.stdout | length > 0 + retries: 30 + delay: 1 + loop: "{{ molecule_instances }}" + loop_control: + label: "{{ item.name }}" + register: molecule_instances_ipv4_output + + - name: Create data for instances IPv4 + ansible.builtin.set_fact: + molecule_instances_ipv4_output: "{{ molecule_instances | map(attribute='name') | list | zip(molecule_instances_ipv4_output.results | map(attribute='stdout') | list) }}" + molecule_instances_ipv4: {} + + - name: Convert list of lists to dictionary + set_fact: + molecule_instances_ipv4: "{{ molecule_instances_ipv4 | combine({item[0]: item[1]}) }}" + loop: "{{ molecule_instances_ipv4_output }}" + loop_control: + label: "{{ item[0] }}" + + when: qemu_vm_network == 'vmnet-shared' ### ssh ################################################################### From d4173603d3c63ad4a6058a5a50d2dd1c4fa71797 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:15:51 +0400 Subject: [PATCH 19/33] update task name --- 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 77952d0..0c64bb5 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -269,7 +269,7 @@ molecule_instances_ipv4_output: "{{ molecule_instances | map(attribute='name') | list | zip(molecule_instances_ipv4_output.results | map(attribute='stdout') | list) }}" molecule_instances_ipv4: {} - - name: Convert list of lists to dictionary + - name: Create mapping for instances IPv4 set_fact: molecule_instances_ipv4: "{{ molecule_instances_ipv4 | combine({item[0]: item[1]}) }}" loop: "{{ molecule_instances_ipv4_output }}" From 21f5e94d73a7304ca5ebeb26551d83df3e4b0312 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:31:49 +0400 Subject: [PATCH 20/33] add user net configuration --- molecule_qemu/playbooks/create.yml | 36 ++++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 0c64bb5..014cb52 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -31,7 +31,6 @@ "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(22) }}", "ssh_user": "{{ item.ssh_user }}", @@ -278,11 +277,28 @@ when: qemu_vm_network == 'vmnet-shared' + ### qemu network: user #################################################### + + - name: Configure QEMU network (user) + block: + - name: Create data for instances IPv4 + ansible.builtin.set_fact: + molecule_instances_ipv4: {} + + - name: Create mapping for instances IPv4 + set_fact: + molecule_instances_ipv4: "{{ molecule_instances_ipv4 | combine({item.name: '127.0.0.1'}) }}" + loop: "{{ molecule_instances }}" + loop_control: + label: "{{ item.name }}" + + when: qemu_vm_network == 'user' + ### ssh ################################################################### - name: Wait for SSH ansible.builtin.wait_for: - host: "{{ item.ssh_host }}" + host: "{{ molecule_instances_ipv4[item.name] }}" port: "{{ item.ssh_port }}" delay: 5 timeout: 180 @@ -290,20 +306,6 @@ loop: "{{ molecule_instances }}" loop_control: label: "{{ item.name }}" - async: 300 - poll: 0 - register: qemu_launch - - - name: Wait for SSH to be ready - ansible.builtin.async_status: - jid: "{{ item.ansible_job_id }}" - loop: "{{ qemu_launch.results }}" - loop_control: - label: "{{ item.item.name }}" - register: qemu_launch_status - until: qemu_launch_status.finished - retries: 30 - delay: 10 ### molecule ############################################################## @@ -312,7 +314,7 @@ instance_conf_dict: { "instance": "{{ item.instance }}", "name": "{{ item.name }}", - "address": "{{ item.ssh_host }}", + "address": "{{ molecule_instances_ipv4[item.name] }}", "user": "{{ item.ssh_user }}", "port": "{{ item.ssh_port }}", "identity_file": "{{ ssh_keypair.filename }}", From 8eb57f76002dfb6bbab1c1ee81ac055d62c4f123 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:37:42 +0400 Subject: [PATCH 21/33] add docs --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 161c73c..ae08eb3 100644 --- a/README.md +++ b/README.md @@ -71,3 +71,8 @@ verifier: * [Ansible](https://www.ansible.com/) * [Molecule](https://molecule.readthedocs.io/en/latest/) * [QEMU](https://www.qemu.org/) + +## QEMU vmnet-shared networking + +* [vmnet.framework modes](https://lore.kernel.org/all/20220315230741.21578-7-Vladislav.Yaroshchuk@jetbrains.com/T/) + From 6c7f3da3cbf3c85f996c7531d58582496563e4be Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:37:50 +0400 Subject: [PATCH 22/33] update assertions --- molecule_qemu/playbooks/create.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 014cb52..376603a 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -60,7 +60,6 @@ - molecule_instances is defined - molecule_instances | length > 0 - molecule_instances | length == molecule_yml.platforms | 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" @@ -86,6 +85,14 @@ ansible.builtin.set_fact: qemu_vm_network: "{{ molecule_instances | map(attribute='vm_network') | list | unique | first }}" + - name: Assert VMs ssh configuration + ansible.builtin.assert: + that: + - molecule_instances | map(attribute='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' + ### capabilities ########################################################## - name: Read kern.hv_support From 38e76f48029e8984da0bf49560c9a690c10d127f Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:49:57 +0400 Subject: [PATCH 23/33] update task names --- molecule_qemu/playbooks/create.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 376603a..396c58a 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -259,7 +259,7 @@ - name: Configure QEMU network (vmnet-shared) block: - - name: Set VMs IPv4 + - name: Set VMs IPv4 (vmnet-shared) ansible.builtin.shell: >- arp -an | grep -i '{{ item.vm_network_mac }}' | awk '{print $2}' | sed 's/[()]//g' until: molecule_instances_ipv4_output.stdout | length > 0 @@ -270,12 +270,12 @@ label: "{{ item.name }}" register: molecule_instances_ipv4_output - - name: Create data for instances IPv4 + - name: Create data for instances IPv4 (vmnet-shared) ansible.builtin.set_fact: molecule_instances_ipv4_output: "{{ molecule_instances | map(attribute='name') | list | zip(molecule_instances_ipv4_output.results | map(attribute='stdout') | list) }}" molecule_instances_ipv4: {} - - name: Create mapping for instances IPv4 + - name: Create mapping for instances IPv4 (vmnet-shared) set_fact: molecule_instances_ipv4: "{{ molecule_instances_ipv4 | combine({item[0]: item[1]}) }}" loop: "{{ molecule_instances_ipv4_output }}" @@ -288,11 +288,11 @@ - name: Configure QEMU network (user) block: - - name: Create data for instances IPv4 + - name: Create data for instances IPv4 (user) ansible.builtin.set_fact: molecule_instances_ipv4: {} - - name: Create mapping for instances IPv4 + - name: Create mapping for instances IPv4 (user) set_fact: molecule_instances_ipv4: "{{ molecule_instances_ipv4 | combine({item.name: '127.0.0.1'}) }}" loop: "{{ molecule_instances }}" From b7af109a772ba2428ba340473e8cea1bf3e0e512 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 22:57:46 +0400 Subject: [PATCH 24/33] add default ipv4 --- molecule_qemu/playbooks/create.yml | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 396c58a..82df961 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -255,6 +255,19 @@ loop_control: label: "{{ item.name }}" + ### qemu network ######################################################### + + - name: Create instances IPv4 empty dict + ansible.builtin.set_fact: + molecule_instances_ipv4: {} + + - name: Create instances IPv4 dict + ansible.builtin.set_fact: + molecule_instances_ipv4: "{{ molecule_instances_ipv4 | combine({item.name: '127.0.0.1'}) }}" + loop: "{{ molecule_instances }}" + loop_control: + label: "{{ item.name }}" + ### qemu network: vmnet-shared ############################################ - name: Configure QEMU network (vmnet-shared) @@ -284,23 +297,6 @@ when: qemu_vm_network == 'vmnet-shared' - ### qemu network: user #################################################### - - - name: Configure QEMU network (user) - block: - - name: Create data for instances IPv4 (user) - ansible.builtin.set_fact: - molecule_instances_ipv4: {} - - - name: Create mapping for instances IPv4 (user) - set_fact: - molecule_instances_ipv4: "{{ molecule_instances_ipv4 | combine({item.name: '127.0.0.1'}) }}" - loop: "{{ molecule_instances }}" - loop_control: - label: "{{ item.name }}" - - when: qemu_vm_network == 'user' - ### ssh ################################################################### - name: Wait for SSH From a2a61b59faa3a4c5fc4d6f4e832fd891d069df41 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 23:01:40 +0400 Subject: [PATCH 25/33] greatly simplify code for arp based ipv4 processing --- molecule_qemu/playbooks/create.yml | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 82df961..0a717c9 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -272,28 +272,23 @@ - name: Configure QEMU network (vmnet-shared) block: - - name: Set VMs IPv4 (vmnet-shared) + - name: Get IPv4 addresses from ARP table (vmnet-shared) ansible.builtin.shell: >- arp -an | grep -i '{{ item.vm_network_mac }}' | awk '{print $2}' | sed 's/[()]//g' - until: molecule_instances_ipv4_output.stdout | length > 0 + until: molecule_instances_arp.stdout | length > 0 retries: 30 delay: 1 loop: "{{ molecule_instances }}" loop_control: label: "{{ item.name }}" - register: molecule_instances_ipv4_output + register: molecule_instances_arp - - name: Create data for instances IPv4 (vmnet-shared) + - name: Create instances IPv4 dict (vmnet-shared) ansible.builtin.set_fact: - molecule_instances_ipv4_output: "{{ molecule_instances | map(attribute='name') | list | zip(molecule_instances_ipv4_output.results | map(attribute='stdout') | list) }}" - molecule_instances_ipv4: {} - - - name: Create mapping for instances IPv4 (vmnet-shared) - set_fact: - molecule_instances_ipv4: "{{ molecule_instances_ipv4 | combine({item[0]: item[1]}) }}" - loop: "{{ molecule_instances_ipv4_output }}" + molecule_instances_ipv4: "{{ molecule_instances_ipv4 | combine({item.item.name: item.stdout}) }}" + loop: "{{ molecule_instances_arp.results }}" loop_control: - label: "{{ item[0] }}" + label: "{{ item.item.name }}" when: qemu_vm_network == 'vmnet-shared' From 7cef6b93a95345bb142a1165d7b4c8ed16a3dde4 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Wed, 31 May 2023 23:06:15 +0400 Subject: [PATCH 26/33] update readme --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ae08eb3..6408537 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,8 @@ Support of other platforms and guest OS is possible, but not tested. molecule init scenario default --driver-name molecule-qemu --verifier-name testinfra ``` -## Example `molecule.yml` +## Example `molecule.yml` for `user` network mode + ```yaml --- dependency: @@ -40,21 +41,56 @@ driver: name: molecule-qemu platforms: - name: ubuntu-1 - image: file:///Users/andrey/Downloads/focal-server-cloudimg-arm64.img + 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: 10022 ssh_user: ubuntu - name: ubuntu-2 - image: file:///Users/andrey/Downloads/focal-server-cloudimg-amd64.img + 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: x86_64 # default ssh_port: 10023 ssh_user: ubuntu - name: debian-1 - image: file:///Users/andrey/Downloads/debian-11-generic-amd64.qcow2 + 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: x86_64 # default ssh_port: 10024 ssh_user: debian +provisioner: + name: ansible +verifier: + name: ansible +``` +## Example `molecule.yml` for `vmnet-shared` network mode + +```yaml +--- +dependency: + name: galaxy +driver: + name: molecule-qemu +platforms: + - name: ubuntu-1 + 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_user: ubuntu + vm_network: vmnet-shared + - name: ubuntu-2 + 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: x86_64 # default + ssh_user: ubuntu + vm_network: vmnet-shared + - name: debian-1 + 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: x86_64 # default + ssh_user: debian + vm_network: vmnet-shared provisioner: name: ansible verifier: From da16a08ee422f901a86eccc9e18f55b72247f820 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Thu, 1 Jun 2023 01:13:29 +0400 Subject: [PATCH 27/33] add docs on network modes --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6408537..561a0fd 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,21 @@ Support guest OS: * Ubuntu 20.04 LTS (x86_64) * Debian 11 (x86_64) -Support of other platforms and guest OS is possible, but not tested. +Support of other platforms and guest OS is possible, but not tested. Please, open an issue if you want to add support for other platforms. + +## Network modes + +### `user` network mode + +This is the default network mode. It uses QEMU's user networking mode. + +Mode is selected by setting `vm_network: user` in `molecule.yml`. + +### `vmnet-shared` network mode + +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`. # Examples From cd91b2bfd37d9e58976f635c488bf2e668976be8 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Thu, 1 Jun 2023 01:17:46 +0400 Subject: [PATCH 28/33] launch as root --- molecule_qemu/playbooks/create.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 0a717c9..f9502ca 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -223,7 +223,12 @@ loop_control: label: "{{ item.name }}" + - name: Launch VMs as priviliged user + ansible.builtin.set_fact: + qemu_privileged: "{{ ( qemu_vm_network == 'vmnet-shared' ) | bool }}" + - name: Launch VMs + become: "{{ qemu_privileged }}" ansible.builtin.command: >- qemu-system-{{ item.image_arch }} -name {{ item.name }} @@ -255,6 +260,15 @@ loop_control: label: "{{ item.name }}" + - name: Allow read access to VMs pid files + become: "{{ qemu_privileged }}" + ansible.builtin.file: + path: "{{ item.path_pid }}" + mode: "0644" + loop: "{{ molecule_instances }}" + loop_control: + label: "{{ item.name }}" + ### qemu network ######################################################### - name: Create instances IPv4 empty dict From 84f7f95efb55e7f3e23b06baf5f7a0d5058f0a5c Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Thu, 1 Jun 2023 01:20:25 +0400 Subject: [PATCH 29/33] bypass privileged to destroy --- molecule_qemu/playbooks/create.yml | 1 + molecule_qemu/playbooks/destroy.yml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index f9502ca..2ad4f08 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -332,6 +332,7 @@ "identity_file": "{{ ssh_keypair.filename }}", "pidfile": "{{ item.path_pid }}", "diskfile": "{{ item.path_disk }}", + "privileged": "{{ qemu_privileged }}", } loop: "{{ molecule_instances }}" loop_control: diff --git a/molecule_qemu/playbooks/destroy.yml b/molecule_qemu/playbooks/destroy.yml index b7f58ce..57a2c8a 100644 --- a/molecule_qemu/playbooks/destroy.yml +++ b/molecule_qemu/playbooks/destroy.yml @@ -24,6 +24,7 @@ register: qemu_processes - name: Destroy running VMs + become: "{{ item.item.privileged | default(false) }}" ansible.builtin.command: > kill {{ item.ansible_facts.pid }} changed_when: false @@ -32,6 +33,7 @@ label: "{{ item.item.name }}" - name: Delete PID files + become: "{{ item.item.privileged | default(false) }}" ansible.builtin.file: path: "{{ item.pidfile }}" state: absent From 20d7457cc9af546167cad60d8fdf9a51b968bd6d Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Thu, 1 Jun 2023 01:21:57 +0400 Subject: [PATCH 30/33] add docs that all modes are mutually exclusive --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 561a0fd..93715c3 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ Support of other platforms and guest OS is possible, but not tested. Please, ope ## Network modes +Network mode is selected by setting `vm_network` in `molecule.yml`. Supported modes are: `user` and `vmnet-shared`. Default mode is `user`. All modes are mutually exclusive. + ### `user` network mode This is the default network mode. It uses QEMU's user networking mode. From b3e6ab81310cc7542adcbe807440d1202f1200f7 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Thu, 1 Jun 2023 01:26:00 +0400 Subject: [PATCH 31/33] update assertion msg --- 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 2ad4f08..64349b9 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -78,8 +78,8 @@ ansible.builtin.assert: that: - molecule_instances | map(attribute='vm_network') | list | unique | length == 1 - fail_msg: "Molecule instances are not the same network" - success_msg: "Molecule instances networks are properly defined" + fail_msg: "Network modes are mutually exclusive" + success_msg: "Network modes are configured properly" - name: Set QEMU network ansible.builtin.set_fact: From 6a3f6fc5c0840c1e73dd12b35f768d783bb3685e Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Thu, 1 Jun 2023 01:37:02 +0400 Subject: [PATCH 32/33] add yamllint --- .yamllint | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .yamllint diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..9e2267a --- /dev/null +++ b/.yamllint @@ -0,0 +1,32 @@ +--- +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + colons: + max-spaces-after: -1 + level: error + commas: + max-spaces-after: -1 + level: error + comments: disable + comments-indentation: disable + document-start: disable + empty-lines: + max: 3 + level: error + hyphens: + level: error + indentation: disable + key-duplicates: enable + line-length: disable + new-line-at-end-of-file: disable + new-lines: + type: unix + trailing-spaces: disable + truthy: disable From a00bd2d25ec009f1a0698ea4689d68a610183e97 Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Thu, 1 Jun 2023 01:37:13 +0400 Subject: [PATCH 33/33] linter --- molecule_qemu/playbooks/create.yml | 42 ++++++++++++++++-------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 64349b9..a333c91 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -38,7 +38,7 @@ "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=item.name) | regex_replace('(^|:)0([0-9A-Fa-f])', '\\1\\2') }}", + "vm_network_mac": "{{ '52:54:00' | community.general.random_mac(seed=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", @@ -225,7 +225,7 @@ - name: Launch VMs as priviliged user ansible.builtin.set_fact: - qemu_privileged: "{{ ( qemu_vm_network == 'vmnet-shared' ) | bool }}" + qemu_privileged: "{{ (qemu_vm_network == 'vmnet-shared') | bool }}" - name: Launch VMs become: "{{ qemu_privileged }}" @@ -285,26 +285,28 @@ ### qemu network: vmnet-shared ############################################ - name: Configure QEMU network (vmnet-shared) + when: qemu_vm_network == 'vmnet-shared' block: - - name: Get IPv4 addresses from ARP table (vmnet-shared) - ansible.builtin.shell: >- - arp -an | grep -i '{{ item.vm_network_mac }}' | awk '{print $2}' | sed 's/[()]//g' - until: molecule_instances_arp.stdout | length > 0 - retries: 30 - delay: 1 - loop: "{{ molecule_instances }}" - loop_control: - label: "{{ item.name }}" - register: molecule_instances_arp - - - name: Create instances IPv4 dict (vmnet-shared) - ansible.builtin.set_fact: - molecule_instances_ipv4: "{{ molecule_instances_ipv4 | combine({item.item.name: item.stdout}) }}" - loop: "{{ molecule_instances_arp.results }}" - loop_control: - label: "{{ item.item.name }}" + - 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' + until: molecule_instances_arp.stdout | length > 0 + retries: 30 + delay: 1 + loop: "{{ molecule_instances }}" + loop_control: + label: "{{ item.name }}" + register: molecule_instances_arp + changed_when: false + + - name: Create instances IPv4 dict (vmnet-shared) + ansible.builtin.set_fact: + molecule_instances_ipv4: "{{ molecule_instances_ipv4 | combine({item.item.name: item.stdout}) }}" + loop: "{{ molecule_instances_arp.results }}" + loop_control: + label: "{{ item.item.name }}" - when: qemu_vm_network == 'vmnet-shared' ### ssh ###################################################################