3 # SPDX-FileCopyrightText: 2021 Ericsson AB and others
5 # SPDX-License-Identifier: Apache-2.0
7 - name: get all running VMs
13 - name: shutdown existing jump VM
15 name: "{{ jumphost.name }}"
18 jumphost.name in running_vms.list_vms
20 - name: get all shutdown VMs
24 register: shutdown_vms
26 - name: undefine existing jump VM
28 name: "{{ jumphost.name }}"
31 jumphost.name in shutdown_vms.list_vms
33 - name: remove dhcp leases
35 jq 'del( .[] | select(.domain == "{{ jumphost.name }}" or .hostname == "{{ jumphost.name }}"))' /var/lib/libvirt/dnsmasq/virbr0.{{ item }} > /tmp/{{ item }}.tmp
36 mv /tmp/{{ item }}.tmp /var/lib/libvirt/dnsmasq/virbr0.{{ item }}
41 when: deployment_type == 'k8s'
43 - name: clean workspace
45 path: "{{ workspace }}"
48 - name: create workspace if it does not exist
50 path: "{{ workspace }}"
54 - name: create directory for base images
56 path: "{{ images_path }}"
60 - name: download Ubuntu image for jump VM
62 url: https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img
63 dest: "{{ images_path }}/bionic-server-cloudimg-amd64.img"
67 - name: create new VM image from base image
68 command: "qemu-img create -f qcow2 -F qcow2 -o backing_file={{ images_path }}/bionic-server-cloudimg-amd64.img {{ workspace }}/{{ jumphost.name }}.qcow2 10G"
70 - name: render config files for jump VM from templates
72 src: "{{ kuberef_root }}/playbooks/roles/jump-vm/templates/{{ item }}.j2"
73 dest: "{{ workspace }}/{{ item }}"
80 - name: create config drive
81 command: "genisoimage -output {{ workspace }}/{{ jumphost.name }}-cidata.iso -volid cidata -joliet -rock \
82 {{ workspace }}/user-data {{ workspace }}/meta-data \
83 {{ workspace + '/network-config' if deployment_type == 'full' else '' }}"
85 # currently commented out because of portability issues between Centos and Ubuntu
86 # - name: setting root password for debugging
88 # command: "virt-customize -a {{ workspace }}/{{ jumphost.name }}.qcow2 --root-password password:'root'"
90 - name: define jump VM
91 command: "virt-install --connect qemu:///system --name {{ jumphost.name }} \
92 --ram 8192 --vcpus=8 --os-type linux --os-variant ubuntu16.04 \
93 --disk path={{ workspace }}/kuberef-jump.qcow2,format=qcow2 \
94 --disk {{ workspace }}/kuberef-jump-cidata.iso,device=cdrom \
95 --network network=default,model=virtio,mac='{{ jumphost.interfaces[engine.net_config[engine.public_network].interface].mac_address }}' \
96 {{ '--network bridge=pxebr,model=rtl8139,mac=' + jumphost.interfaces[engine.net_config[engine.pxe_network].interface].mac_address if deployment_type == 'full' else '' }} \
97 --import --noautoconsole"
101 name: "{{ jumphost.name }}"
104 - name: wait for ip to be visible
105 shell: virsh domifaddr "{{ jumphost.name }}" --full | grep "{{ jumphost.interfaces[engine.net_config[engine.public_network].interface].mac_address }}" | awk '{print $4}' | tail -n 1
109 until: ipblock.stdout != ""
110 when: deployment_type == 'k8s'
114 vm_ip: "{{ ipblock.stdout.split('/') }}"
115 when: deployment_type == 'k8s'
117 - name: wait for VM to be reachable
119 host: "{{ ( vm_ip is defined and vm_ip.0 or '' ) if 'k8s' in deployment_type else jumphost.interfaces[idf.net_config[engine.pxe_network].interface].address | default('') }}"